What is the cleanest way to stop a python multiprocessing worker attached to a queue in an infinite loop?
问题 I'm implementing a producer-consumer pattern in python using multiprocessing.Pool and multiprocessing.Queue . Consumers are pre-forked processes that uses gevent to spawn multiple tasks. Here is a trimmed down version of code: import gevent from Queue import Empty as QueueEmpty from multiprocessing import Process, Queue, Pool import signal import time # Task queue queue = Queue() def init_worker (): # Ignore signals in worker signal.signal( signal.SIGTERM, signal.SIG_IGN ) signal.signal(