Skip to content

Commit 3090524

Browse files
committed
Store Py_MAX result in a variable.
It re-evaluates it, apparently.
1 parent 354e6b5 commit 3090524

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Lib/threading.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,8 +1557,9 @@ def _shutdown():
15571557
# normally - that won't happen until the interpreter is nearly dead. So
15581558
# mark it done here.
15591559
if _main_thread._os_thread_handle.is_done() and _is_main_interpreter():
1560-
# _shutdown() was already called
1561-
return False
1560+
# _shutdown() was already called, but threads might have started
1561+
# in the meantime.
1562+
return _thread_shutdown()
15621563

15631564
global _SHUTTING_DOWN
15641565
_SHUTTING_DOWN = True

Python/pylifecycle.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,10 +2013,12 @@ make_pre_finalization_calls(PyThreadState *tstate)
20132013
int called = 0;
20142014

20152015
// Wrap up existing "threading"-module-created, non-daemon threads.
2016-
called = Py_MAX(called, wait_for_thread_shutdown(tstate));
2016+
int threads_joined = wait_for_thread_shutdown(tstate);
2017+
called = Py_MAX(called, threads_joined);
20172018

20182019
// Make any remaining pending calls.
2019-
called = Py_MAX(called, _Py_FinishPendingCalls(tstate));
2020+
int made_pending_calls = _Py_FinishPendingCalls(tstate);
2021+
called = Py_MAX(called, made_pending_calls);
20202022

20212023
/* The interpreter is still entirely intact at this point, and the
20222024
* exit funcs may be relying on that. In particular, if some thread
@@ -2028,7 +2030,8 @@ make_pre_finalization_calls(PyThreadState *tstate)
20282030
* the threads created via Threading.
20292031
*/
20302032

2031-
called = Py_MAX(called, _PyAtExit_Call(tstate->interp));
2033+
int called_atexit = _PyAtExit_Call(tstate->interp);
2034+
called = Py_MAX(called, called_atexit);
20322035

20332036
if (called == 0) {
20342037
break;

0 commit comments

Comments
 (0)