【问题标题】:Python 3 threading.enumerate() exceptionPython 3 threading.enumerate() 异常
【发布时间】:2017-06-09 02:12:15
【问题描述】:

我正在编写基于 django 的网络,我的应用程序正在其中运行。用户传递一些参数,应用程序在自己的线程中启动。出于调试目的,我想打印以控制台所有活动线程。我使用 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() 创建的虚拟线程对象和主线程。它不包括已终止的线程和尚未启动的线程。

【问题讨论】:

    标签: django multithreading python-3.x exception enums


    【解决方案1】:

    我认为这可能是打印问题

    试试这个:

    for thread in threading._enumerate(): print(thread.name)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-10
      相关资源
      最近更新 更多