我正在编写基于django的web,我的应用程序就在这里运行。用户传递一些参数,应用程序就会在自己的线程中启动。出于调试目的,我希望将所有活动线程打印到控制台。我使用python线程模块和以下代码:
import threading
def some_func():
print(threading.enumerate())
.
.
.此调用会导致以下异常:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\django\core\handlers\exception.py", line 39, in inner
response = get_response(request)
File "C:\Python34\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python34\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\bakajsa\AppData\Local\Programs\Git\mysite\my_project\views.py", line 90, in some_func
print(threading.enumerate())
File "C:\Python34\lib\threading.py", line 824, in __repr__
self.is_alive() # easy way to get ._is_stopped set when appropriate
File "C:\Python34\lib\threading.py", line 1120, in is_alive
self._wait_for_tstate_lock(False)
File "C:\Python34\lib\threading.py", line 1076, in _wait_for_tstate_lock
assert self._is_stopped
AssertionError你知道会出什么问题吗?
根据文档:
threading.enumerate()
返回当前活动的所有Thread对象的列表。该列表包括守护线程、由current_thread()创建的虚拟线程对象和主线程。它不包括已终止的线程和尚未启动的线程。
发布于 2018-03-12 19:42:40
我想这可能是打印的问题
试试这个:
for thread in threading._enumerate(): print(thread.name)
https://stackoverflow.com/questions/41825476
复制相似问题