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
This commit is contained in:
Abhishek Kekane 2016-02-03 22:58:21 -08:00
parent 0b906a1c3e
commit c8305399cf
1 changed files with 10 additions and 0 deletions

View File

@ -1079,6 +1079,16 @@ class WebSocketServer(object):
except (self.Terminate, SystemExit, KeyboardInterrupt): except (self.Terminate, SystemExit, KeyboardInterrupt):
self.msg("In exit") 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 break
except Exception: except Exception:
exc = sys.exc_info()[1] exc = sys.exc_info()[1]