Right now _DummyThread claims to not allow join:
|
def is_alive(self): |
|
assert not self._is_stopped and self._started.is_set() |
|
return True |
|
|
|
def join(self, timeout=None): |
|
assert False, "cannot join a dummy thread" |
But, it can be easily changed with python -OO mode, which strips assert statements.
The easiest way to check this is:
# ex.py
import threading, _thread
def f(mutex):
threading.current_thread()
mutex.release()
mutex = threading.Lock()
mutex.acquire()
tid = _thread.start_new_thread(f, (mutex,))
mutex.acquire()
threading._active[tid].join()
print('done')
python ex.py results in:
Traceback (most recent call last):
File "/Users/sobolev/Desktop/cpython/ex.py", line 12, in <module>
threading._active[tid].join()
File "/Users/sobolev/Desktop/cpython/Lib/threading.py", line 1458, in join
assert False, "cannot join a dummy thread"
AssertionError: cannot join a dummy thread
But, python -OO ex.py results in:
This looks like an important behavior change. I propose to use explicit AssertionError / RuntimeError instead.
I have a PR ready.
Linked PRs
Right now
_DummyThreadclaims to not allowjoin:cpython/Lib/threading.py
Lines 1453 to 1458 in fb0d9b9
But, it can be easily changed with
python -OOmode, which stripsassertstatements.The easiest way to check this is:
python ex.pyresults in:But,
python -OO ex.pyresults in:This looks like an important behavior change. I propose to use explicit
AssertionError/RuntimeErrorinstead.I have a PR ready.
Linked PRs
assertwithraise RuntimeErrorinthreading.py#106237