I am trying to program a Python3 module that when run, will (1) start up a server on some localhost port, and (2) open the file being served on that server.
The main design decision for me at this point was having a function return the server's endpoint while keeping it running. I wanted something short and simple.
I had a few possibilities for a solution, such as generators and the other options listed in the "motivation" section of this PEP entry from this answer.
What seemed simplest to me was a run_server()
function which would basically use a SimpleHTTPRequestHandler
to serve at a specific port with a specific timeout. A start_server()
function would the start a thread with run_server as its target, start the thread, and return the server's endpoint.
However, as a soon-to-be grad who is still learning proper usage of threading, I'm not sure that this is best practice/good design for what I am trying to achieve as far as threading is concerned. After having finished my undergrad, I look back at things I programmed in high school thinking they were brilliant solutions, horrified by how many best practice flaws/overcomplications they have.
Is this considered an OK thing to do as far as server startup/threading is concerned?