summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2016-05-09 18:18:29 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2016-05-10 02:15:35 +0200
commit357ad2bc8700f44a3df2caaf5297a0395103a988 (patch)
tree1fc57b075637ec9d927575a6e38a6fc9b3e4014a
parenta7293a22f7e6c0b255d6e33572740a12ed844092 (diff)
downloadbot-357ad2bc8700f44a3df2caaf5297a0395103a988.tar.gz
bot-357ad2bc8700f44a3df2caaf5297a0395103a988.tar.bz2
bot-357ad2bc8700f44a3df2caaf5297a0395103a988.zip
Watcher: Fork while starting watching not while configuring
-rwxr-xr-x__init__.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/__init__.py b/__init__.py
index 91c7440..1c171fa 100755
--- a/__init__.py
+++ b/__init__.py
@@ -13,18 +13,31 @@ import bot
class Watcher(object):
# Cf. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496735
def __init__(self):
+ self._configs = []
self._children = []
signal.signal(signal.SIGTERM, self.sig_term)
def add(self, config):
+ self._configs.append(config)
+
+ def _start(self, config):
child = os.fork()
if child != 0:
self._children.append(child)
else:
run_phenny(config)
+ def run(self):
+ for config in self._configs:
+ self._start(config)
+
def watch(self):
- try: os.wait()
+ self.run()
+
+ try:
+ proc = None
+ while proc not in self._children:
+ (proc, _) = os.wait()
except KeyboardInterrupt:
self.kill()
sys.exit()
@@ -49,8 +62,8 @@ def run_phenny(config):
while True:
try: connect(config)
- except KeyboardInterrupt:
- sys.exit()
+ except KeyboardInterrupt, e:
+ raise e
if not isinstance(delay, int):
break
@@ -59,6 +72,7 @@ def run_phenny(config):
print >> sys.stderr, warning
time.sleep(delay)
+
def run(configs):
w = Watcher()
for config in configs: