Python3でmultiprocessing.Processを使用して終了したプロセスがすべての子プロセスを再帰的に終了させる方法は?

Python3でmultiprocessing.Processを使用して終了したプロセスがすべての子プロセスを再帰的に終了させる方法は?

子プロセス内に子プロセスを作成し、親プロセスが終了したら、各子プロセスが繰り返し終了するようにしたいと思います。

私は現在、プログラミング言語としてPythonを使用していますが、プログラミング言語に拘束されないソリューションを探しています。

私を混乱させるのは、それぞれがパラメータProcessに従って「デーモン」または「ビデーモン」で構成されることです。このパラメーターは、親プロセスが終了したときに子プロセスが終了するかどうかを制御します。daemon__init__()

ただし、次の資料に示すように、aがProcess「デーモンプロセス」の場合、子プロセスを作成できないため、私が望むことを達成することはできません。つまり、親プロセスが終了したときに子プロセスを再帰的に終了します。

https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Process.daemon:

daemon
The process’s daemon flag, a Boolean value. This must be set before start() is called.

The initial value is inherited from the creating process.

When a process exits, it attempts to terminate all of its daemonic child processes.

Note that a daemonic process is not allowed to create child processes. Otherwise a daemonic process would leave its children orphaned if it gets terminated when its parent process exits. Additionally, these are not Unix daemons or services, they are normal processes that will be terminated (and not joined) if non-daemonic processes have exited.

ベストアンサー1

おすすめ記事