From 7509077504112a6a0bd9a78d44b9af4c26fac49f Mon Sep 17 00:00:00 2001 From: Abhishek Kekane Date: Wed, 3 Feb 2016 22:58:21 -0800 Subject: [PATCH] Make websockify respect SIGTERM Child processes were not terminated when the parent websockify was killed. This commit makes websockify send a SIGTERM to all active children when the parent process is terminated. Fixes #138 --- websockify/websocket.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/websockify/websocket.py b/websockify/websocket.py index cfa47ad..16e1dc4 100644 --- a/websockify/websocket.py +++ b/websockify/websocket.py @@ -1079,6 +1079,14 @@ class WebSocketServer(object): except (self.Terminate, SystemExit, KeyboardInterrupt): self.msg("In exit") + # terminate all child processes + if multiprocessing and not self.run_once: + children = multiprocessing.active_children() + + for child in children: + self.msg("Terminating child %s" % child.pid) + child.terminate() + break except Exception: exc = sys.exc_info()[1]