Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ def f(mutex):
#Issue 29376
self.assertTrue(threading._active[tid].is_alive())
self.assertRegex(repr(threading._active[tid]), '_DummyThread')

# Issue gh-106236:
with self.assertRaises(RuntimeError):
threading._active[tid].join()
threading._active[tid]._started.clear()
with self.assertRaises(RuntimeError):
threading._active[tid].is_alive()

del threading._active[tid]

# PyThreadState_SetAsyncExc() is a CPython-only gimmick, not (currently)
Expand Down
7 changes: 4 additions & 3 deletions Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1451,11 +1451,12 @@ def _stop(self):
pass

def is_alive(self):
assert not self._is_stopped and self._started.is_set()
return True
if not self._is_stopped and self._started.is_set():
return True
raise RuntimeError("thread is not alive")

def join(self, timeout=None):
assert False, "cannot join a dummy thread"
raise RuntimeError("cannot join a dummy thread")


# Global API functions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Replace ``assert`` statements with ``raise RuntimeError`` in
:mod:`threading`, so that ``_DummyThread`` cannot be joined even with ``-OO``.