Skip to content

Commit

Permalink
pythongh-106236: Replace assert with raise AssertionError in `thr…
Browse files Browse the repository at this point in the history
…eading.py`
  • Loading branch information
sobolevn committed Jun 29, 2023
1 parent fb0d9b9 commit 2070971
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Lib/test/test_threading.py
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(AssertionError):
threading._active[tid].join()
threading._active[tid]._started.clear()
with self.assertRaises(AssertionError):
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
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 AssertionError("thread is not alive")

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


# Global API functions
Expand Down
@@ -0,0 +1,3 @@
Replace ``assert`` statements with ``raise AssertionError`` in
:mod:`threading`, so the behaviour of ``_DummyThread`` with and without
``-OO`` is consistent.

0 comments on commit 2070971

Please sign in to comment.