8000 gh-132578: Rename the `threading.Thread._handle` field (GH-132696) · miss-islington/cpython@d59d1d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit d59d1d5

Browse files
mpagemiss-islington
authored andcommitted
pythongh-132578: Rename the threading.Thread._handle field (pythonGH-132696)
Commit `0e9c364f` introduced the `_handle` field on instances of `threading.Thread`. Unfortunately it's fairly common for subclasses of `threading.Thread` to define a `_handle()` method, which is shadowed by the new field. (cherry picked from commit 3cfab44) Co-authored-by: mpage <mpage@meta.com>
1 parent e140e6e commit d59d1d5

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

Lib/threading.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ class is implemented.
916916
self._ident = None
917917
if _HAVE_THREAD_NATIVE_ID:
918918
self._native_id = None
919-
self._handle = _ThreadHandle()
919+
self._os_thread_handle = _ThreadHandle()
920920
self._started = Event()
921921
self._initialized = True
922922
# Copy of sys.stderr used by self._invoke_excepthook()
@@ -931,7 +931,7 @@ def _after_fork(self, new_ident=None):
931931
if new_ident is not None:
932932
# This thread is alive.
933933
self._ident = new_ident
934-
assert self._handle.ident == new_ident
934+
assert self._os_thread_handle.ident == new_ident
935935
else:
936936
# Otherwise, the thread is dead, Jim. _PyThread_AfterFork()
937937
# already marked our handle done.
@@ -942,7 +942,7 @@ def __repr__(self):
942942
status = "initial"
943943
if self._started.is_set():
944944
status = "started"
945-
if self._handle.is_done():
945+
if self._os_thread_handle.is_done():
946946
status = "stopped"
947947
if self._daemonic:
948948
status += " daemon"
@@ -970,7 +970,7 @@ def start(self):
970970
_limbo[self] = self
971971
try:
972972
# Start joinable thread
973-
_start_joinable_thread(self._bootstrap, handle=self._handle,
973+
_start_joinable_thread(self._bootstrap, handle=self._os_thread_handle,
974974
daemon=self.daemon)
975975
except Exception:
976976
with _active_limbo_lock:
@@ -1089,7 +1089,7 @@ def join(self, timeout=None):
10891089
if timeout is not None:
10901090
timeout = max(timeout, 0)
10911091

1092-
self._handle.join(timeout)
1092+
self._os_thread_handle.join(timeout)
10931093

10941094
@property
10951095
def name(self):
@@ -1140,7 +1140,7 @@ def is_alive(self):
11401140
11411141
"""
11421142
assert self._initialized, "Thread.__init__() not called"
1143-
return self._started.is_set() and not self._handle.is_done()
1143+
return self._started.is_set() and not self._os_thread_handle.is_done()
11441144

11451145
@property
11461146
def daemon(self):
@@ -1351,7 +1351,7 @@ def __init__(self):
13511351
Thread.__init__(self, name="MainThread", daemon=False)
13521352
self._started.set()
13531353
self._ident = _get_main_thread_ident()
1354-
self._handle = _make_thread_handle(self._ident)
1354+
self._os_thread_handle = _make_thread_handle(self._ident)
13551355
if _HAVE_THREAD_NATIVE_ID:
13561356
self._set_native_id()
13571357
with _active_limbo_lock:
@@ -1399,15 +1399,15 @@ def __init__(self):
13991399
daemon=_daemon_threads_allowed())
14001400
self._started.set()
14011401
self._set_ident()
1402-
self._handle = _make_thread_handle(self._ident)
1402+
self._os_thread_handle = _make_thread_handle(self._ident)
14031403
if _HAVE_THREAD_NATIVE_ID:
14041404
self._set_native_id()
14051405
with _active_limbo_lock:
14061406
_active[self._ident] = self
14071407
_DeleteDummyThreadOnDel(self)
14081408

14091409
def is_alive(self):
1410-
if not self._handle.is_done() and self._started.is_set():
1410+
if not self._os_thread_handle.is_done() and self._started.is_set():
14111411
return True
14121412
raise RuntimeError("thread is not alive")
14131413

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

@@ -1534,7 +1534,7 @@ def _shutdown():
15341534
atexit_call()
15351535

15361536
if _is_main_interpreter():
1537-
_main_thread._handle._set_done()
1537+
_main_thread._os_thread_handle._set_done()
15381538

15391539
# Wait for all non-daemon threads to exit.
15401540
_thread_shutdown()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Rename the ``threading.Thread._handle`` field to avoid shadowing methods
2+
defined on subclasses of ``threading.Thread``.

0 commit comments

Comments
 (0)
0