diff options
-rwxr-xr-x | __init__.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/__init__.py b/__init__.py index 91c7440..1c171fa 100755 --- a/__init__.py +++ b/__init__.py @@ -13,18 +13,31 @@ import bot class Watcher(object): # Cf. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496735 def __init__(self): + self._configs = [] self._children = [] signal.signal(signal.SIGTERM, self.sig_term) def add(self, config): + self._configs.append(config) + + def _start(self, config): child = os.fork() if child != 0: self._children.append(child) else: run_phenny(config) + def run(self): + for config in self._configs: + self._start(config) + def watch(self): - try: os.wait() + self.run() + + try: + proc = None + while proc not in self._children: + (proc, _) = os.wait() except KeyboardInterrupt: self.kill() sys.exit() @@ -49,8 +62,8 @@ def run_phenny(config): while True: try: connect(config) - except KeyboardInterrupt: - sys.exit() + except KeyboardInterrupt, e: + raise e if not isinstance(delay, int): break @@ -59,6 +72,7 @@ def run_phenny(config): print >> sys.stderr, warning time.sleep(delay) + def run(configs): w = Watcher() for config in configs: |