SimpleHTTPServer launched as a thread: does not daemonize

假如想象 提交于 2019-12-05 01:34:22

Change this:

thread = threading.Thread(target = server.serve_forever())

To be this:

thread = threading.Thread(target = server.serve_forever)

And change this:

thread.setdaemon = True

To be this:

thread.daemon = True

Try thread = threading.Thread(target = server.serve_forever), i.e. without the call.

The problem with your version is that serve_forever() is called on parsing the line where the thread is created. Thus, you never get to the next line.

The argument type must be callable, which will be called on thread start, so you need to pass name, server.serve_forever instead of trying to pass result of executing this function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!