Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 63 lines (49 sloc) 1.38 KB
#!/usr/bin/env python
""" - Phenny Init Module
Copyright 2008, Sean B. Palmer,
Licensed under the Eiffel Forum License 2.
import sys, os, time, threading, signal
import bot
class Watcher(object):
# Cf.
def __init__(self):
self.child = os.fork()
if self.child != 0:
def watch(self):
try: os.wait()
except KeyboardInterrupt:
def kill(self):
try: os.kill(self.child, signal.SIGKILL)
except OSError: pass
def run_phenny(config):
if hasattr(config, 'delay'):
delay = config.delay
else: delay = 20
def connect(config):
p = bot.Phenny(config), config.port)
try: Watcher()
except Exception, e:
print >> sys.stderr, 'Warning:', e, '(in'
while True:
try: connect(config)
except KeyboardInterrupt:
if not isinstance(delay, int):
warning = 'Warning: Disconnected. Reconnecting in %s seconds...' % delay
print >> sys.stderr, warning
def run(config):
t = threading.Thread(target=run_phenny, args=(config,))
if hasattr(t, 'run'):
else: t.start()
if __name__ == '__main__':
print __doc__