From ce1940017869c8d78bd3b3cbb0ab9a33d61dd743 Mon Sep 17 00:00:00 2001 From: benoitc Date: Mon, 8 Aug 2011 14:05:55 +0200 Subject: [PATCH] provides a decent default to let the worker notify the arbiter. and modify example to use it --- examples/hello.py | 7 ++----- pistil/worker.py | 10 +++++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/hello.py b/examples/hello.py index 5425ab3..70f4686 100644 --- a/examples/hello.py +++ b/examples/hello.py @@ -11,11 +11,8 @@ class MyWorker(Worker): - def run(self): - - while True: - print "hello from worker n°%s" % self.pid - time.sleep(1) + def handle(self): + print "hello from worker n°%s" % self.pid if __name__ == "__main__": diff --git a/pistil/worker.py b/pistil/worker.py index 6aeb462..adaca1e 100644 --- a/pistil/worker.py +++ b/pistil/worker.py @@ -9,6 +9,7 @@ import os import signal import sys +import time import traceback @@ -65,13 +66,20 @@ def notify(self): """ self.tmp.notify() + + def handle(self): + raise NotImplementedError + def run(self): """\ This is the mainloop of a worker process. You should override this method in a subclass to provide the intended behaviour for your particular evil schemes. """ - raise NotImplementedError() + while True: + self.notify() + self.handle() + time.sleep(0.1) def on_init_process(self): """ method executed when we init a process """