python-daemonを使用する場合、次のようなサブプロセスを作成しています。
import multiprocessing
class Worker(multiprocessing.Process):
def __init__(self, queue):
self.queue = queue # we wait for things from this in Worker.run()
...
q = multiprocessing.Queue()
with daemon.DaemonContext():
for i in xrange(3):
Worker(q)
while True: # let the Workers do their thing
q.put(_something_we_wait_for())
Ctrl-C や SIGTERM などで親のデーモン プロセス (ワーカーではないプロセス) を強制終了しても、子プロセスは終了しません。どうやって子供を殺しますか?
私の最初の考えは、atexitを使用してすべてのワーカーを殺すことです。
with daemon.DaemonContext():
workers = list()
for i in xrange(3):
workers.append(Worker(q))
@atexit.register
def kill_the_children():
for w in workers:
w.terminate()
while True: # let the Workers do their thing
q.put(_something_we_wait_for())
ただし、デーモンの子は扱いが難しいため、これをどのように行うべきかについての考えと情報を提供していただきたいと思います。
ありがとうございました。