mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-23 23:58:12 +08:00
Better exit strategy:
-Pusher is stopped -Poison pills are put on the task queue -Wait for workers to clear the queue and exit -Poison pill is put in the result queue -Main process exits when monitor has finished processing results
This commit is contained in:
+9
-3
@@ -108,11 +108,17 @@ class Cluster(object):
|
||||
logger.info('{} stopping pool processes'.format(name))
|
||||
# Stopping pusher
|
||||
self.event_stop.set()
|
||||
# Stopping monitor
|
||||
self.done_queue.put('STOP')
|
||||
# Stopping workers
|
||||
# Putting poison pills in the queue
|
||||
for _ in self.pool:
|
||||
self.task_queue.put('STOP')
|
||||
while len(self.pool) > 2:
|
||||
for p in list(self.pool):
|
||||
if not p.is_alive():
|
||||
logger.debug('{} stopped gracefully'.format(p.pid))
|
||||
self.pool.remove(p)
|
||||
sleep(0.2)
|
||||
# Finally stop the monitor
|
||||
self.done_queue.put('STOP')
|
||||
|
||||
def sig_handler(self, signum, frame):
|
||||
logger.debug('{} got signal {}'.format(current_process().name, SIGNAL_NAMES.get(signum, 'UNKNOWN')))
|
||||
|
||||
Reference in New Issue
Block a user