Pylons / waitress

Waitress - A WSGI server for Python 3
https://docs.pylonsproject.org/projects/waitress/en/latest/
Other
1.44k stars 164 forks source link

Waitress thread does not respect daemon property. #410

Closed dstathis closed 1 year ago

dstathis commented 1 year ago

I have the following code:

server_thread = threading.Thread(target=waitress.serve, args=(app,))
server_thread.daemon = False  # Makes this thread exit when the main thread exits.
server_thread.start()

return

I would expect the server to stop after the main thread returns. Reading the threading documentation:

daemon
A boolean value indicating whether this thread is a daemon thread (True) or not (False). This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when no alive non-daemon threads are left.

I don't understand the internals of waitress well enough to understand what's going on here but presumably the threads inside waitress are created with something other than threading.Thread and are therefore not inheriting the daemon property.

Is there a way to make this work the way I want? Or perhaps to shutdown the server thread with code some other way?

dstathis commented 1 year ago

Never mind it was a typo. "False" should have been "True".