Building Rich a Dev Server
Draft Post
I’ve really been digging @willmcgugan’s [1]
rich [2] library for creating TUI like
interfaces in python. I’ve only recently started to take full advantage of it.
Dev Server # [3]
I am working on a project in which I want to have a dev
server running continuously in the background. I really
like dev servers theat automatically chooose an unused
port and list out the running pid so that I can kill it if
I need to.
- automatic port number
- auto-restart
- display ( port, pid, uptime )
finding the port # [4]
I am very novice at best when it comes to sockets, the following function came
from searching StackOverflow for how to tell if a port is in use. I
recursively check if a port is being used, if it is I increment by one until I
find an unused port to return.
def find_port(port=8000):
"""Find a port not in ues starting at given port"""
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
if s.connect_ex(("localhost", port)) == 0:
return f...