SocketServer continues execution after serve_forever

I am using the SocketServer module in python to implement a simple embedded web server in my application. I am currently calling the serve_forver method on a dedicated thread to continue running my application.

I was wondering if there is an even more pythonic way to launch my SocketServer and reconfigure the execution in my application.

+4
source share
1 answer

This is a very Putin way:

threading.Thread(target=myServer.serve_forever).start() 

I do not see how this can be obscure or overly verbose. If you want the program to exit after the main thread completes, add daemon=True to the Thread call.

An alternative is to call handle_request in a loop on your own, but this is not like your case with the web server.

+8
source

All Articles