【发布时间】:2013-01-05 18:38:12
【问题描述】:
大家晚上好。我正在使用 Python 2.7 和 threading 模块编写多线程程序。这是一个代码示例:
# Importing myFunc function which will be run in the new thread
from src.functions import myFunc
# Importing a threading module
import threading
# Creating and running new thread initiated by our function
# and some parameters.
t = threading.Thread(target=myFunc, args=(1, 2, 3))
t.start()
我知道在 C++(POSIX 线程库)中,有一个 pthread_detach() 函数可以将正在运行的线程置于分离状态。它保证该线程在函数结束后将资源释放回系统。那么,在 Python 中有没有类似这样的函数?或者说,Python中根本不需要分离线程,线程占用的资源会在线程函数结束后自动释放?
我试图搜索docs.python.org和谷歌的信息,但没有结果。
【问题讨论】: