Skip to content

Commit 447d655

Browse files
committed
Add test for detaching from self
1 parent 3358737 commit 447d655

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Lib/test/test_thread.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,33 @@ def task():
235235
with self.assertRaisesRegex(RuntimeError, "Cannot join current thread"):
236236
raise errors[0]
237237

238+
def test_detach_from_self(self):
239+
errors = []
240+
start_new_thread_returned = thread.allocate_lock()
241+
start_new_thread_returned.acquire()
242+
thread_detached = thread.allocate_lock()
243+
thread_detached.acquire()
244+
245+
def task():
246+
ident = thread.get_ident()
247+
start_new_thread_returned.acquire()
248+
try:
249+
thread.detach_thread(ident)
250+
except Exception as e:
251+
errors.append(e)
252+
finally:
253+
thread_detached.release()
254+
255+
with threading_helper.wait_threads_exit():
256+
joinable = True
257+
ident = thread.start_new_thread(task, (), {}, joinable)
258+
start_new_thread_returned.release()
259+
thread_detached.acquire()
260+
with self.assertRaisesRegex(ValueError, "not joinable"):
261+
thread.join_thread(ident)
262+
263+
assert len(errors) == 0
264+
238265
def test_detach_then_join(self):
239266
lock = thread.allocate_lock()
240267
lock.acquire()

0 commit comments

Comments
 (0)