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:
Ilan Steemers
2015-06-18 17:55:52 +02:00
parent bed64c7313
commit e6cfdf6a1f
+9 -3
View File
@@ -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')))