7
7
__copyright__ = 'this file is in the public domain'
9
9
from gozerbot.thr import start_new_thread
10
from gozerbot.generic import handle_exception, rlog
16
self.queue = Queue.Queue()
21
def put(self, descr, func, *args, **kwargs):
22
self.queue.put_nowait((descr, func, args, kwargs))
26
start_new_thread(self.run, ())
27
rlog(1, 'runner', 'started runner thread')
32
self.queue.put_nowait((None, None, None, None))
36
while not self.dostop:
37
(descr, func, args, kwargs) = self.queue.get()
41
rlog(1, 'runner', 'running %s: %s' % (descr, str(func)))
44
elapsed = time.time() - start
46
rlog(10, 'runner', 'ALERT %s %s job taking too long: %s \
10
from gozerbot.generic import handle_exception, rlog, lockdec
11
from gozerbot.threadloop import ThreadLoop
12
import Queue, time, thread
14
runlock = thread.allocate_lock()
15
locked = lockdec(runlock)
17
class Runner(ThreadLoop):
20
def handle(self, descr, func, *args, **kwargs):
22
rlog(1, 'runner', 'running %s: %s' % (descr, str(func)))
25
elapsed = time.time() - start
27
rlog(10, 'runner', 'ALERT %s %s job taking too long: %s \
47
28
seconds' % (descr, str(func), elapsed))
50
rlog(10, 'runner', 'stopped runner thread')
32
runner = Runner('runner')