From c8305399cf38968deac477177f5828653007e51b Mon Sep 17 00:00:00 2001 From: Abhishek Kekane Date: Wed, 3 Feb 2016 22:58:21 -0800 Subject: [PATCH] websockify does not react to SIGTERM Child processes are not terminated when parent process of websockify is killed. In this fix made provision to terminate all child processes when parent process is killed. Fixes #138 --- websockify/websocket.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/websockify/websocket.py b/websockify/websocket.py index cfa47ad..3888ba0 100644 --- a/websockify/websocket.py +++ b/websockify/websocket.py @@ -1079,6 +1079,16 @@ class WebSocketServer(object): except (self.Terminate, SystemExit, KeyboardInterrupt): self.msg("In exit") + # terminate all child processes + if multiprocessing and not self.run_once: + childs = multiprocessing.active_children() + + for child in childs: + pid = child.pid + if pid != os.getpid(): + self.msg("Terminating child %s" % pid) + os.kill(pid, signal.SIGTERM) + break except Exception: exc = sys.exc_info()[1]