diff --git a/__init__.py b/__init__.py index 5699583aa..e6f2b7555 100755 --- a/__init__.py +++ b/__init__.py @@ -10,11 +10,18 @@ import sys, os, time, threading, signal import bot -class Watcher(object): +class Watcher(object): # Cf. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496735 - def __init__(self): + def __init__(self, config_file): + config_dir = os.path.dirname(config_file) + config_name = os.path.basename(config_file).split('.')[0] self.child = os.fork() - if self.child != 0: + if self.child != 0: + f = open('%s/phenny.%s.pid' % (config_dir, config_name), 'w') + try: + f.write(str(self.child)) + finally: + f.close() self.watch() def watch(self): @@ -36,8 +43,8 @@ def connect(config): p = bot.Phenny(config) p.run(config.host, config.port) - try: Watcher() - except Exception, e: + try: Watcher(config.filename) + except Exception, e: print >> sys.stderr, 'Warning:', e, '(in __init__.py)' while True: