mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-07 23:28:11 +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))
|
logger.info('{} stopping pool processes'.format(name))
|
||||||
# Stopping pusher
|
# Stopping pusher
|
||||||
self.event_stop.set()
|
self.event_stop.set()
|
||||||
# Stopping monitor
|
# Putting poison pills in the queue
|
||||||
self.done_queue.put('STOP')
|
|
||||||
# Stopping workers
|
|
||||||
for _ in self.pool:
|
for _ in self.pool:
|
||||||
self.task_queue.put('STOP')
|
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):
|
def sig_handler(self, signum, frame):
|
||||||
logger.debug('{} got signal {}'.format(current_process().name, SIGNAL_NAMES.get(signum, 'UNKNOWN')))
|
logger.debug('{} got signal {}'.format(current_process().name, SIGNAL_NAMES.get(signum, 'UNKNOWN')))
|
||||||
|
|||||||
Reference in New Issue
Block a user