diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2016-05-10 02:09:51 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2016-05-10 02:16:58 +0200 |
commit | cd524df0d7ab2660ebba23d0b22be3cd83152e4d (patch) | |
tree | 3ea2a9e36c261df61ab00ebf267f91695f253e3e | |
parent | 844eafc830247c704a620ebdd54835e343ce1ad5 (diff) | |
download | bot-cd524df0d7ab2660ebba23d0b22be3cd83152e4d.tar.gz bot-cd524df0d7ab2660ebba23d0b22be3cd83152e4d.tar.bz2 bot-cd524df0d7ab2660ebba23d0b22be3cd83152e4d.zip |
Watcher: Delay restart of dead processes
-rwxr-xr-x | __init__.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/__init__.py b/__init__.py index 9c6bcdc..33c68a9 100755 --- a/__init__.py +++ b/__init__.py @@ -20,13 +20,13 @@ class Watcher(object): def add(self, config): self._configs.append(config) - def _start(self, config): + def _start(self, config, restart=False): child = os.fork() if child != 0: self._children[child] = config else: signal.signal(signal.SIGTERM, signal.SIG_DFL) - run_phenny(config) + run_phenny(config, restart) def run(self): for config in self._configs: @@ -61,7 +61,7 @@ class Watcher(object): self.kill() sys.exit() -def run_phenny(config): +def run_phenny(config, restart): if hasattr(config, 'delay'): delay = config.delay else: delay = 20 @@ -70,6 +70,11 @@ def run_phenny(config): p = bot.Phenny(config) p.run(config.host, config.port, config.ssl) + if restart: + warning = 'Reconnecting in %s seconds...' % delay + print >> sys.stderr, warning + time.sleep(delay) + while True: try: connect(config) except KeyboardInterrupt, e: |