diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2016-05-09 18:20:00 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2016-05-10 02:15:36 +0200 |
commit | 1058c16c5b19c0ec43c14e8f23c796c346411b68 (patch) | |
tree | 8a0c4e5c89cffbb48e7066f47355de57942c5f8d | |
parent | 357ad2bc8700f44a3df2caaf5297a0395103a988 (diff) | |
download | bot-1058c16c5b19c0ec43c14e8f23c796c346411b68.tar.gz bot-1058c16c5b19c0ec43c14e8f23c796c346411b68.tar.bz2 bot-1058c16c5b19c0ec43c14e8f23c796c346411b68.zip |
Watcher: Loop until KeyboardInterrupt
Kill and restart the bots if one dies until the main process is killed by
KeyboardInterrupt.
-rwxr-xr-x | __init__.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/__init__.py b/__init__.py index 1c171fa..d3f6b06 100755 --- a/__init__.py +++ b/__init__.py @@ -32,13 +32,17 @@ class Watcher(object): self._start(config) def watch(self): - self.run() + alive = True + while alive: + self.run() + + try: + proc = None + while proc not in self._children: + (proc, _) = os.wait() + except KeyboardInterrupt: + alive = False - try: - proc = None - while proc not in self._children: - (proc, _) = os.wait() - except KeyboardInterrupt: self.kill() sys.exit() @@ -46,6 +50,7 @@ class Watcher(object): for child in self._children: try: os.kill(child, signal.SIGKILL) except OSError: pass + self._children = [] def sig_term(self, signum, frame): self.kill() |