diff options
author | Solly Ross <sross@redhat.com> | 2013-10-21 16:50:52 -0400 |
---|---|---|
committer | Solly Ross <sross@redhat.com> | 2013-10-21 16:52:42 -0400 |
commit | 53f1f1989ecf3d3086242831c74faa3801026f37 (patch) | |
tree | 7e8db5b781553bc77f274f08ea5e57d455b28aa4 | |
parent | a61ae52610642ae58e914dda705df8bb9c8213ec (diff) | |
download | websockify-53f1f1989ecf3d3086242831c74faa3801026f37.tar.gz |
Handle SIGCHLD properly for multiprocessing
This commit should fix #101 by enabling a special SIGCHLD
handler for when multiprocessing is in use. The handler
simply calls `multiprocessing.active_children()` (which in
turn calls `_cleanup()`) upon receiving a SIGCHLD. Now,
the `fallback_SIGCHLD` is only called when `multiprocessing`
is not in use. See also #95.
-rw-r--r-- | websockify/websocket.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/websockify/websocket.py b/websockify/websocket.py index 2548fb8..c40e638 100644 --- a/websockify/websocket.py +++ b/websockify/websocket.py @@ -696,6 +696,9 @@ Sec-WebSocket-Accept: %s\r def terminate(self): raise self.Terminate() + def multiprocessing_SIGCHLD(self, sig, stack): + self.vmsg('Reaing zombies, active child count is %s', len(multiprocessing.active_children())) + def fallback_SIGCHLD(self, sig, stack): # Reap zombies when using os.fork() (python 2.4) self.vmsg("Got SIGCHLD, reaping zombies") @@ -796,7 +799,13 @@ Sec-WebSocket-Accept: %s\r } signal.signal(signal.SIGINT, self.do_SIGINT) signal.signal(signal.SIGTERM, self.do_SIGTERM) - signal.signal(signal.SIGCHLD, self.fallback_SIGCHLD) + if not multiprocessing: + # os.fork() (python 2.4) child reaper + signal.signal(signal.SIGCHLD, self.fallback_SIGCHLD) + else: + # make sure that _cleanup is called when children die + # by calling active_children on SIGCHLD + signal.signal(signal.SIGCHLD, self.multiprocessing_SIGCHLD) last_active_time = self.launch_time try: |