开始一个单独的过程 [英] Starting a separate process
问题描述
我希望脚本启动一个新进程,以便新进程在初始脚本退出后继续运行.我希望可以使用multiprocessing.Process
来启动新进程,并设置daemon=True
以便在创建的进程继续运行时退出主脚本.
I want a script to start a new process, such that the new process continues running after the initial script exits. I expected that I could use multiprocessing.Process
to start a new process, and set daemon=True
so that the main script may exit while the created process continues running.
但是,当主脚本退出时,第二个进程似乎被静默终止.这是预期的行为,还是我做错了什么?
But it seems that the second process is silently terminated when the main script exits. Is this expected behavior, or am I doing something wrong?
推荐答案
来自Python文档:
From the Python docs:
当进程退出时,它将尝试执行以下操作: 终止其所有守护进程子进程 程序.
When a process exits, it attempts to terminate all of its daemonic child processes.
这是预期的行为.
这篇关于开始一个单独的过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!