summaryrefslogtreecommitdiffstats
path: root/__init__.py
diff options
context:
space:
mode:
authorSean B. Palmer <http://inamidst.com/sbp/>2008-03-02 11:16:25 +0000
committerSean B. Palmer <http://inamidst.com/sbp/>2008-03-02 11:16:25 +0000
commit23c1dffa101536889dd6bcef198233ee980add7f (patch)
treea60d4934705193bd282f002708c9e34c3b80191e /__init__.py
parent1078791cb60d3ce4543d579fc07b9c0c145e8d10 (diff)
downloadbot-23c1dffa101536889dd6bcef198233ee980add7f.tar.gz
bot-23c1dffa101536889dd6bcef198233ee980add7f.tar.bz2
bot-23c1dffa101536889dd6bcef198233ee980add7f.zip
Fixed some .u stuff, added .bytes, and made Ctrl+C work.
Diffstat (limited to '__init__.py')
-rwxr-xr-x__init__.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/__init__.py b/__init__.py
index 8137683..752fd02 100755
--- a/__init__.py
+++ b/__init__.py
@@ -7,9 +7,26 @@ Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
"""
-import sys, time, threading
+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:
+ self.watch()
+
+ 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 run_phenny(config):
if hasattr(config, 'delay'):
delay = config.delay
@@ -19,6 +36,7 @@ def run_phenny(config):
p = bot.Phenny(config)
p.run(config.host)
+ Watcher()
while True:
connect(config)
if not isinstance(delay, int): break