I'm using the SocketServer module in python to implement a simple embedded web server in my application. At the moment I'm calling the serve_forver method within a dedicated thread in order to continue the execution of my application.
I was wondering if there is there a more pythonic way to start my SocketServer and retun the execution to my application.
That is a very pythonic way:
threading.Thread(target=myServer.serve_forever).start()
I don't see how that could be unclear or overly verbose. If you want the program to exit once your main thread finishes, add daemon=True
to the Thread
call.
An alternative is calling handle_request
in a loop yourself, but that doesn't seem applicable to your case of a web-server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With