Closed bwindsor closed 1 year ago
You might look at the StoppableWSGIServer in webtest which is doing the right thing. I’m not saying it shouldn’t be in waitress but incase you weren’t aware this does work.
Thanks - I was aware that something in webtest exists, but this isn't only for the purposes of unit tests, I also need to be able to shut down my production system gracefully. In the system I'm not running waitress in isolation, it's one of a handful of threads doing different things. I could run it in its own process and then kill the process to ensure it's all cleaned up, but that adds extra complexity.
You can see several related tickets already in waitress around getting the shutdown to be properly graceful. Your suggestions won’t get it to that point.
In that case, let's close this so that I'm not creating unnecessary noise, and leave it to be included in the bigger changes for fully graceful shutdown. Thanks for the quick replies!
Thanks! The graceful shutdown is tricky and neither @bertjwregeer nor I have had time to get into the nitty gritty of it, despite it being important.
It requires configuring waitress to stop listening for new connections but keep asyncore open (but stop listening) to continue processing existing connections to a point before ultimately shutting things down when those active requests are complete.
Example to reproduce the issue:
I would expect that after calling
close
on the server, threads would be cleaned up rather than left to hang around as daemons. InMultiSocketServer
it looks like this issue is solved: https://github.com/Pylons/waitress/blob/afc7b9de54f21b63bb1e8fd6b12c704876d9868a/src/waitress/server.py#L175But in
BaseWSGIServer
it does not attempt to shutdown thetask_dispatcher
as part of theclose
method. https://github.com/Pylons/waitress/blob/afc7b9de54f21b63bb1e8fd6b12c704876d9868a/src/waitress/server.py#L357-L359A simple solution would be to add
self.task_dispatcher.shutdown()
to theclose()
method.