classification
Title: repr(threading._DummyThread) always fails.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: fabioz, pitrou
Priority: normal Keywords:

Created on 2018-05-23 17:39 by fabioz, last changed 2018-05-24 10:56 by fabioz. This issue is now closed.

Messages (4)
msg317430 - (view) Author: Fabio Zadrozny (fabioz) * Date: 2018-05-23 17:39
Doing the following throws an exception:

import threading
repr(threading._DummyThread())


Or, in a more contrived example (I actually had this in a QThread, so, reproducing using getting the current_thread using a thread created with the _thread module):

import threading
import traceback
finished = threading.Event()
worked = []
def method():
    try:
        repr(threading.current_thread())
        worked.append(True)
    except:
        traceback.print_exc()
        worked.append(False)
    finally:
        finished.set()
    
import _thread
_thread.start_new_thread(method, ())

finished.wait()
assert worked[0]
msg317543 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2018-05-24 08:07
Can you post the actual exception you are getting?

Here I have:

>>> import threading
>>> repr(threading._DummyThread())
'<_DummyThread(Dummy-1, started daemon 140345620215552)>'
msg317552 - (view) Author: Fabio Zadrozny (fabioz) * Date: 2018-05-24 10:55
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import threading
>>> repr(threading._DummyThread())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\tools\Miniconda\envs\pyqt5\lib\threading.py", line 819, in __repr__
    self.is_alive() # easy way to get ._is_stopped set when appropriate
  File "C:\tools\Miniconda\envs\pyqt5\lib\threading.py", line 1115, in is_alive
    self._wait_for_tstate_lock(False)
  File "C:\tools\Miniconda\envs\pyqt5\lib\threading.py", line 1071, in _wait_for_tstate_lock
    assert self._is_stopped
AssertionError
msg317553 - (view) Author: Fabio Zadrozny (fabioz) * Date: 2018-05-24 10:56
Actually, I tried on a more recent version of Python 3.6 (3.6.5) and it doesn't happen there (so, just happens in 3.6.0 -- i.e.: in the old conda env I had around).

Sorry for the noise. Closing issue as it's already fixed.
History
Date User Action Args
2018-05-24 10:56:56fabiozsetstatus: open -> closed

messages: + msg317553
stage: resolved
2018-05-24 10:55:06fabiozsetmessages: + msg317552
2018-05-24 08:07:41pitrousetnosy: + pitrou
messages: + msg317543
2018-05-23 17:39:42fabiozcreate