Skip to content

Commit 4b6c417

Browse files
authored
bpo-29376: Fix assertion error in threading._DummyThread.is_alive() (GH-330)
1 parent 7e4897a commit 4b6c417

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

Lib/test/test_threading.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ def f(mutex):
170170
mutex.acquire()
171171
self.assertIn(tid, threading._active)
172172
self.assertIsInstance(threading._active[tid], threading._DummyThread)
173+
#Issue 29376
174+
self.assertTrue(threading._active[tid].is_alive())
175+
self.assertRegex(repr(threading._active[tid]), '_DummyThread')
173176
del threading._active[tid]
174177

175178
# PyThreadState_SetAsyncExc() is a CPython-only gimmick, not (currently)

Lib/threading.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,10 @@ def __init__(self):
12171217
def _stop(self):
12181218
pass
12191219

1220+
def is_alive(self):
1221+
assert not self._is_stopped and self._started.is_set()
1222+
return True
1223+
12201224
def join(self, timeout=None):
12211225
assert False, "cannot join a dummy thread"
12221226

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Extension Modules
6969
Library
7070
-------
7171

72+
- bpo-29376: Fix assertion error in threading._DummyThread.is_alive().
73+
7274
- bpo-28624: Add a test that checks that cwd parameter of Popen() accepts
7375
PathLike objects. Patch by Sayan Chowdhury.
7476

0 commit comments

Comments
 (0)