fix Worker.wait
This commit is contained in:
parent
c9333adc5c
commit
cffe8cea08
@ -191,7 +191,7 @@ def make_app(conf):
|
|||||||
|
|
||||||
isso = Isso(conf, cacheobj, dbobj)
|
isso = Isso(conf, cacheobj, dbobj)
|
||||||
|
|
||||||
atexit.register(worker.join, 0.25)
|
atexit.register(worker.join, 0.1)
|
||||||
worker.start()
|
worker.start()
|
||||||
|
|
||||||
# check HTTP server connection
|
# check HTTP server connection
|
||||||
|
@ -130,7 +130,7 @@ class Worker(threading.Thread):
|
|||||||
:param queue: a Queue
|
:param queue: a Queue
|
||||||
:param targets: a mapping of task names and the actual task objects"""
|
:param targets: a mapping of task names and the actual task objects"""
|
||||||
|
|
||||||
interval = 0.05
|
interval = 0.1
|
||||||
|
|
||||||
def __init__(self, queue, targets):
|
def __init__(self, queue, targets):
|
||||||
super(Worker, self).__init__()
|
super(Worker, self).__init__()
|
||||||
@ -148,7 +148,7 @@ class Worker(threading.Thread):
|
|||||||
try:
|
try:
|
||||||
payload = self.queue.get()
|
payload = self.queue.get()
|
||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
Worker.wait(0.5)
|
self.wait(10)
|
||||||
else:
|
else:
|
||||||
task = self.targets.get(payload.type)
|
task = self.targets.get(payload.type)
|
||||||
if task is None:
|
if task is None:
|
||||||
@ -175,16 +175,17 @@ class Worker(threading.Thread):
|
|||||||
self.alive = False
|
self.alive = False
|
||||||
super(Worker, self).join(timeout)
|
super(Worker, self).join(timeout)
|
||||||
|
|
||||||
@classmethod
|
def wait(self, seconds):
|
||||||
def wait(cls, seconds):
|
|
||||||
"""Sleep for :param seconds: but split into :var interval: sleeps to
|
"""Sleep for :param seconds: but split into :var interval: sleeps to
|
||||||
be interruptable.
|
be interruptable.
|
||||||
"""
|
"""
|
||||||
f, i = math.modf(seconds / Worker.interval)
|
f, i = math.modf(seconds / Worker.interval)
|
||||||
|
|
||||||
for x in range(int(i)):
|
for x in range(int(i)):
|
||||||
|
if self.alive:
|
||||||
time.sleep(Worker.interval)
|
time.sleep(Worker.interval)
|
||||||
|
|
||||||
|
if self.alive:
|
||||||
time.sleep(f * Worker.interval)
|
time.sleep(f * Worker.interval)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user