diff options
Diffstat (limited to '__init__.py')
-rwxr-xr-x | __init__.py | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/__init__.py b/__init__.py index fa76316..6c94555 100755 --- a/__init__.py +++ b/__init__.py @@ -10,58 +10,58 @@ http://inamidst.com/phenny/ import sys, os, time, threading, signal import bot -class Watcher(object): - # Cf. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496735 - def __init__(self): - self.child = os.fork() - if self.child != 0: - signal.signal(signal.SIGTERM, self.sig_term) - self.watch() +class Watcher(object): + # Cf. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496735 + def __init__(self): + self.child = os.fork() + if self.child != 0: + signal.signal(signal.SIGTERM, self.sig_term) + self.watch() - def watch(self): - try: os.wait() - except KeyboardInterrupt: - self.kill() - sys.exit() + def watch(self): + try: os.wait() + except KeyboardInterrupt: + self.kill() + sys.exit() - def kill(self): - try: os.kill(self.child, signal.SIGKILL) - except OSError: pass + def kill(self): + try: os.kill(self.child, signal.SIGKILL) + except OSError: pass - def sig_term(self, signum, frame): - self.kill() - sys.exit() + def sig_term(self, signum, frame): + self.kill() + sys.exit() -def run_phenny(config): - if hasattr(config, 'delay'): - delay = config.delay - else: delay = 20 +def run_phenny(config): + if hasattr(config, 'delay'): + delay = config.delay + else: delay = 20 - def connect(config): - p = bot.Phenny(config) - p.run(config.host, config.port) + def connect(config): + p = bot.Phenny(config) + p.run(config.host, config.port) - try: Watcher() - except Exception, e: - print >> sys.stderr, 'Warning:', e, '(in __init__.py)' + try: Watcher() + except Exception, e: + print >> sys.stderr, 'Warning:', e, '(in __init__.py)' - while True: - try: connect(config) - except KeyboardInterrupt: - sys.exit() + while True: + try: connect(config) + except KeyboardInterrupt: + sys.exit() - if not isinstance(delay, int): - break + if not isinstance(delay, int): + break - warning = 'Warning: Disconnected. Reconnecting in %s seconds...' % delay - print >> sys.stderr, warning - time.sleep(delay) + warning = 'Warning: Disconnected. Reconnecting in %s seconds...' % delay + print >> sys.stderr, warning + time.sleep(delay) -def run(config): - t = threading.Thread(target=run_phenny, args=(config,)) - if hasattr(t, 'run'): - t.run() - else: t.start() +def run(config): + t = threading.Thread(target=run_phenny, args=(config,)) + if hasattr(t, 'run'): + t.run() + else: t.start() -if __name__ == '__main__': - print __doc__ +if __name__ == '__main__': + print __doc__ |