Skip to content

Commit 2cf0e73

Browse files
committed
Add test for Thread.join(timeout)
1 parent c39d7a0 commit 2cf0e73

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Lib/test/test_threading.py

+15
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,21 @@ def joiner(thread):
508508
if errors:
509509
raise errors[0]
510510

511+
def test_join_with_timeout(self):
512+
lock = _thread.allocate_lock()
513+
lock.acquire()
514+
515+
def worker():
516+
lock.acquire()
517+
518+
thread = threading.Thread(target=worker)
519+
thread.start()
520+
thread.join(timeout=0.01)
521+
assert thread.is_alive()
522+
lock.release()
523+
thread.join()
524+
assert not thread.is_alive()
525+
511526
def test_no_refcycle_through_target(self):
512527
class RunSelfFunction(object):
513528
def __init__(self, should_raise):

Lib/threading.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1254,9 +1254,10 @@ def is_alive(self):
12541254
if self._is_stopped or not self._started.is_set():
12551255
return False
12561256
self._wait_for_tstate_lock(False)
1257-
if self._is_stopped:
1258-
self._join_os_thread()
1259-
return not self._is_stopped
1257+
if not self._is_stopped:
1258+
return True
1259+
self._join_os_thread()
1260+
return False
12601261

12611262
@property
12621263
def daemon(self):

0 commit comments

Comments
 (0)