开发者

SocketServer continue execution after serve_forever

I'm using the SocketServer module in pyth开发者_Python百科on 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜