[issue7978] SocketServer doesn't handle syscall interruption

Bryce Allen report at bugs.python.org
Wed Apr 28 21:58:21 CEST 2010

Bryce Allen <oss at bda.ath.cx> added the comment:

I encountered this issue when trying to exit cleanly on SIGTERM, which I use to terminate background daemons running serve_forever.

In BaseServer, a threading.Event is used in shutdown, so it can block until server_forever is finished (after checking __serving). Since the SIGTERM interrupts the select system call, the event set is never reached, and shutdown hangs waiting on the event.

I've attached an example of the pattern I was trying to use in my server. There are several ways around the issue, but looking at the API it seems like this _should_ work, and in my experience all servers have clean-up code so it's a very common case.

nosy: +bda
Added file: http://bugs.python.org/file17120/sockServe.py

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list