Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down