有没有任何方法可以知道哪些线程正在使用python线程模块运行。通过下面的代码,我可以获得线程名称、当前线程、活动线程计数。在
但我怀疑的是活动线程是2,而当前线程总是“MainThread”。在后台运行的另一个线程可能是什么?在
import threading
import time
for _ in range(10):
time.sleep(3)
print("\n", threading.currentThread().getName())
print("current thread", threading.current_thread())
print("active threads ", threading.active_count())
主线程
当前线程<;\u MainThread(主线程,开始于11008)>
2个活动线程
您可以使用^{} 访问所有当前线程对象,例如
相关问题 更多 >
编程相关推荐