Skip to content

gh-104341: Minor Fixes in the _thread Module #104595

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

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 0 additions & 2 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ struct _is {
uint64_t next_unique_id;
/* The linked list of threads, newest first. */
PyThreadState *head;
/* Used in Modules/_threadmodule.c. */
long count;
/* Support for runtime thread stack size tuning.
A value of 0 means using the platform's default stack size
or the size specified by the THREAD_STACK_SIZE macro. */
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def run(self):

def test_limbo_cleanup(self):
# Issue 7481: Failure to start thread should cleanup the limbo map.
def fail_new_thread(*args):
def fail_new_thread(*args, **kwargs):
raise threading.ThreadError()
_start_new_thread = threading._start_new_thread
threading._start_new_thread = fail_new_thread
Expand Down
8 changes: 7 additions & 1 deletion Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
except AttributeError:
_CRLock = None
TIMEOUT_MAX = _thread.TIMEOUT_MAX
try:
_internal_after_fork = _thread._after_fork
except AttributeError:
_internal_after_fork = None
del _thread


Expand Down Expand Up @@ -968,7 +972,7 @@ def start(self):
with _active_limbo_lock:
_limbo[self] = self
try:
_start_new_thread(self._bootstrap, ())
_start_new_thread(self._bootstrap, (), daemonic=self._daemonic)
except Exception:
with _active_limbo_lock:
del _limbo[self]
Expand Down Expand Up @@ -1677,4 +1681,6 @@ def _after_fork():


if hasattr(_os, "register_at_fork"):
if _internal_after_fork is not None:
_os.register_at_fork(after_in_child=_internal_after_fork)
_os.register_at_fork(after_in_child=_after_fork)
Loading