mirror of
https://github.com/python/cpython.git
synced 2025-09-19 07:00:59 +00:00
gh-106236: Replace assert
with raise RuntimeError
in threading.py
(#106237)
Replace `assert` with `raise ` in `threading.py` so that -OO does not alter _DummyThread behavior.
This commit is contained in:
parent
dd1884dc5d
commit
e4b88c1e4a
3 changed files with 14 additions and 3 deletions
|
@ -251,6 +251,14 @@ class ThreadTests(BaseTestCase):
|
||||||
#Issue 29376
|
#Issue 29376
|
||||||
self.assertTrue(threading._active[tid].is_alive())
|
self.assertTrue(threading._active[tid].is_alive())
|
||||||
self.assertRegex(repr(threading._active[tid]), '_DummyThread')
|
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]
|
del threading._active[tid]
|
||||||
|
|
||||||
# PyThreadState_SetAsyncExc() is a CPython-only gimmick, not (currently)
|
# PyThreadState_SetAsyncExc() is a CPython-only gimmick, not (currently)
|
||||||
|
|
|
@ -1451,11 +1451,12 @@ class _DummyThread(Thread):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def is_alive(self):
|
def is_alive(self):
|
||||||
assert not self._is_stopped and self._started.is_set()
|
if not self._is_stopped and self._started.is_set():
|
||||||
return True
|
return True
|
||||||
|
raise RuntimeError("thread is not alive")
|
||||||
|
|
||||||
def join(self, timeout=None):
|
def join(self, timeout=None):
|
||||||
assert False, "cannot join a dummy thread"
|
raise RuntimeError("cannot join a dummy thread")
|
||||||
|
|
||||||
|
|
||||||
# Global API functions
|
# Global API functions
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Replace ``assert`` statements with ``raise RuntimeError`` in
|
||||||
|
:mod:`threading`, so that ``_DummyThread`` cannot be joined even with ``-OO``.
|
Loading…
Add table
Add a link
Reference in a new issue