8000 gh-132578: Rename the `threading.Thread._handle` field by mpage · Pull Request #132696 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-132578: Rename the threading.Thread._handle field #132696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
8000
22 changes: 11 additions & 11 deletions Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ class is implemented.
self._ident = None
if _HAVE_THREAD_NATIVE_ID:
self._native_id = None
self._handle = _ThreadHandle()
self._os_thread_handle = _ThreadHandle()
self._started = Event()
self._initialized = True
# Copy of sys.stderr used by self._invoke_excepthook()
Expand All @@ -950,7 +950,7 @@ def _after_fork(self, new_ident=None):
if new_ident is not None:
# This thread is alive.
self._ident = new_ident
assert self._handle.ident == new_ident
assert self._os_thread_handle.ident == new_ident
else:
# Otherwise, the thread is dead, Jim. _PyThread_AfterFork()
# already marked our handle done.
Expand All @@ -961,7 +961,7 @@ def __repr__(self):
status = "initial"
if self._started.is_set():
status = "started"
if self._handle.is_done():
if self._os_thread_handle.is_done():
status = "stopped"
if self._daemonic:
status += " daemon"
Expand Down Expand Up @@ -999,7 +999,7 @@ def start(self):

try:
# Start joinable thread
_start_joinable_thread(self._bootstrap, handle=self._handle,
_start_joinable_thread(self._bootstrap, handle=self._os_thread_handle,
daemon=self.daemon)
except Exception:
with _active_limbo_lock:
Expand Down Expand Up @@ -1127,7 +1127,7 @@ def join(self, timeout=None):
if timeout is not None:
timeout = max(timeout, 0)

self._handle.join(timeout)
self._os_thread_handle.join(timeout)

@property
def name(self):
Expand Down Expand Up @@ -1180,7 +1180,7 @@ def is_alive(self):

"""
assert self._initialized, "Thread.__init__() not called"
return self._started.is_set() and not self._handle.is_done()
return self._started.is_set() and not self._os_thread_handle.is_done()

@property
def daemon(self):
Expand Down Expand Up @@ -1391,7 +1391,7 @@ def __init__(self):
Thread.__init__(self, name="MainThread", daemon=False)
self._started.set()
self._ident = _get_main_thread_ident()
self._handle = _make_thread_handle(self._ident)
self._os_thread_handle = _make_thread_handle(self._ident)
if _HAVE_THREAD_NATIVE_ID:
self._set_native_id()
with _active_limbo_lock:
Expand Down Expand Up @@ -1439,15 +1439,15 @@ def __init__(self):
daemon=_daemon_threads_allowed())
self._started.set()
self._set_ident()
self._handle = _make_thread_handle(self._ident)
self._os_thread_handle = _make_thread_handle(self._ident)
if _HAVE_THREAD_NATIVE_ID:
self._set_native_id()
with _active_limbo_lock:
_active[self._ident] = self
_DeleteDummyThreadOnDel(self)

def is_alive(self):
if not self._handle.is_done() and self._started.is_set():
if not self._os_thread_handle.is_done() and self._started.is_set():
return True
raise RuntimeError("thread is not alive")

Expand Down Expand Up @@ -1561,7 +1561,7 @@ def _shutdown():
# dubious, but some code does it. We can't wait for it to be marked as done
# normally - that won't happen until the interpreter is nearly dead. So
# mark it done here.
if _main_thread._handle.is_done() and _is_main_interpreter():
if _main_thread._os_thread_handle.is_done() and _is_main_interpreter():
# _shutdown() was already called
return

Expand All @@ -1574,7 +1574,7 @@ def _shutdown():
atexit_call()

if _is_main_interpreter():
_main_thread._handle._set_done()
_main_thread._os_thread_handle._set_done()

# Wait for all non-daemon threads to exit.
_thread_shutdown()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Rename the ``threading.Thread._handle`` field to avoid shadowing methods
defined on subclasses of ``threading.Thread``.
Loading
0