Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test_tstate_lock -> test_running_lock.
  • Loading branch information
ericsnowcurrently committed May 24, 2023
commit 2eefddde040347a0638ab80f2b67143266cd046c
24 changes: 12 additions & 12 deletions 24 Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ def f():
rc, out, err = assert_python_ok("-c", code)
self.assertEqual(err, b"")

def test_tstate_lock(self):
def test_running_lock(self):
# Test an implementation detail of Thread objects.
started = _thread.allocate_lock()
finish = _thread.allocate_lock()
Expand All @@ -757,29 +757,29 @@ def f():
started.release()
finish.acquire()
time.sleep(0.01)
# The tstate lock is None until the thread is started
# The running lock is None until the thread is started
t = threading.Thread(target=f)
self.assertIs(t._tstate_lock, None)
self.assertIs(t._running_lock, None)
t.start()
started.acquire()
self.assertTrue(t.is_alive())
# The tstate lock can't be acquired when the thread is running
# The running lock can't be acquired when the thread is running
# (or suspended).
tstate_lock = t._tstate_lock
self.assertFalse(tstate_lock.acquire(timeout=0), False)
running_lock = t._running_lock
self.assertFalse(running_lock.acquire(timeout=0), False)
finish.release()
# When the thread ends, the state_lock can be successfully
# acquired.
self.assertTrue(tstate_lock.acquire(timeout=support.SHORT_TIMEOUT), False)
# But is_alive() is still True: we hold _tstate_lock now, which
# prevents is_alive() from knowing the thread's end-of-life C code
self.assertTrue(running_lock.acquire(timeout=support.SHORT_TIMEOUT), False)
# But is_alive() is still True: we hold _running_lock now, which
# prevents is_alive() from knowing the thread's Python code
# is done.
self.assertTrue(t.is_alive())
# Let is_alive() find out the C code is done.
tstate_lock.release()
running_lock.release()
self.assertFalse(t.is_alive())
# And verify the thread disposed of _tstate_lock.
self.assertIsNone(t._tstate_lock)
# And verify the thread disposed of _running_lock.
self.assertIsNone(t._running_lock)
t.join()

def test_repr_stopped(self):
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.