当我打电话os.fork()
守护线程内,在子进程的主线程有daemon
属性设置为True
。这非常令人困惑,因为程序保持运行,而唯一的线程是守护进程。根据文档,如果所有的线程都是守护进程,程序应该退出。在守护进程线程中创建的进程的主线程是守护进程本身吗?
下面是一个例子:
import os
import threading
def child():
assert not threading.current_thread().daemon # This shouldn't fail
def parent():
new_pid = os.fork()
if new_pid == 0:
child()
else:
os.waitpid(new_pid, 0)
t = threading.Thread(target=parent)
t.setDaemon(True)
t.start()
t.join()
是它的CPython的实现中的错误?
我是否正确地纠正你的问题? –
是的,谢谢! –