sách gpt4 ai đã đi

thread.start_new_thread so với threading.Thread.start

In lại Tác giả: Space Dog 更新时间:2023-10-29 20:50:36 28 4
mua khóa gpt4 Nike

python中的thread.start_new_threadthreading.Thread.startSự khác biệt là gì?
我注意到,当调用 start_new_thread 时,新线程会在调用线程终止后立即终止。 threading.Thread.start 则相反:调用线程等待其他线程终止。

1 Câu trả lời

chủ đề 模块是 Python 的低级线程 API。除非您确实需要,否则不建议直接使用它。 xâu chuỗi 模块是一个高级 API,构建在 chủ đề 之上。 Thread.start方法实际上是使用thread.start_new_thread实现的。

Chủ đề củadaemon 属性必须在调用bắt đầu 之前设置,指定线程是否应该是守护进程。当没有留下任何事件的非守护线程时,整个 Python 程序就会退出。默认情况下,daemonSAI,因此该线程不是守护进程,因此该进程将等待其所有非守护线程退出,这是您的行为正在观察。


附言start_new_thread 真的很底层。它只是 Python 核心线程启动器的一个薄包装,它本身调用操作系统线程生成函数。

关于python - thread.start_new_thread 与 threading.Thread.start,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5882362/

28 4 0
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com