Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
354e6b5
Execute early finalization handlers in a loop
ZeroIntensity Jun 26, 2025
3090524
Store Py_MAX result in a variable.
ZeroIntensity Jun 26, 2025
43038b8
Add a test in test_atexit.
ZeroIntensity Jun 26, 2025
8d4151c
Deal with it in Py_EndInterpreter() as well.
ZeroIntensity Jun 26, 2025
add4d33
Add a blurb entry.
ZeroIntensity Jun 26, 2025
3edc3a8
Check the return code in the test.
ZeroIntensity Jun 26, 2025
ec57918
Add a test for pending calls.
ZeroIntensity Jun 26, 2025
970153b
Fix tests on Windows.
ZeroIntensity Jun 26, 2025
cfd62b8
Use os.linesep.
ZeroIntensity Jul 3, 2025
859070f
Use an RW lock instead of a counter.
ZeroIntensity Jul 3, 2025
37098a0
Merge branch 'main' of https://github.com/python/cpython into fix-cir…
ZeroIntensity Jul 3, 2025
8a1aa13
Remove more counters.
ZeroIntensity Jul 3, 2025
cbcd552
Remove old artifacts (again).
ZeroIntensity Jul 9, 2025
54613a1
Final time removing artifacts.
ZeroIntensity Jul 9, 2025
9ccdb5f
(I lied)
ZeroIntensity Jul 9, 2025
9cd75b7
Atomically check if there are threads, atexit callbacks, or pending c…
ZeroIntensity Jul 9, 2025
1360059
Remove stray newline change.
ZeroIntensity Jul 9, 2025
475538a
Add a test for atexit with subinterpreters.
ZeroIntensity Jul 10, 2025
a794188
Check for os.pipe() in the test.
ZeroIntensity Jul 10, 2025
2dda7a4
Rely on stop-the-world and the GIL instead of a dedicated RW mutex.
ZeroIntensity Jul 10, 2025
f1460af
Serialize pending calls via the ceval mutex.
ZeroIntensity Jul 10, 2025
1e1301d
Only check for non-daemon threads at finalization.
ZeroIntensity Jul 10, 2025
51a20d4
Fix assertion failures on the GILful build.
ZeroIntensity Jul 24, 2025
cf2dc1e
Merge branch 'main' into fix-circular-finalization
ZeroIntensity Sep 17, 2025
6ea3792
Merge branch 'main' of https://github.com/python/cpython into fix-cir…
ZeroIntensity Sep 17, 2025
8c12e6c
Fix merge conflict artifact.
ZeroIntensity Sep 17, 2025
8b87014
Improve comments.
ZeroIntensity Sep 17, 2025
e57bfde
Merge branch 'fix-circular-finalization' of https://github.com/zeroin…
ZeroIntensity Sep 17, 2025
e202848
Fix ordering of finalization calls.
ZeroIntensity Sep 17, 2025
0e66c88
Finalize subinterpreters as a pre-finalization check.
ZeroIntensity Sep 18, 2025
c8cac69
Merge branch 'main' of https://github.com/python/cpython into fix-cir…
ZeroIntensity Sep 18, 2025
2ab28b0
Test _PyEval_AddPendingCall() instead of Py_AddPendingCall()
ZeroIntensity Sep 18, 2025
c9d5f4c
Add a test for subinterpreters.
ZeroIntensity Sep 18, 2025
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
Next Next commit
Fix assertion failures on the GILful build.
There were assertions that required the world to be stopped, but since
that isn't a thing on GILful builds, it caused failures. Protect those
assertions with a macro.
  • Loading branch information
ZeroIntensity committed Jul 24, 2025
commit 51a20d416f9408d956936263fe57fc44ca1edb85
16 changes: 11 additions & 5 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -2003,13 +2003,19 @@ resolve_final_tstate(_PyRuntimeState *runtime)
return main_tstate;
}

#ifdef Py_GIL_DISABLED
#define ASSERT_WORLD_STOPPED(interp) assert(interp->runtime->stoptheworld.world_stopped)
#else
#define ASSERT_WORLD_STOPPED(interp)
#endif

static int
interp_has_threads(PyInterpreterState *interp)
{
/* This needs to check for non-daemon threads only, otherwise we get stuck
* in an infinite loop. */
assert(interp != NULL);
assert(interp->runtime->stoptheworld.world_stopped);
ASSERT_WORLD_STOPPED(interp);
assert(interp->threads.head != NULL);
if (interp->threads.head->next == NULL) {
// No other threads active, easy way out.
Expand All @@ -2031,7 +2037,7 @@ static int
interp_has_pending_calls(PyInterpreterState *interp)
{
assert(interp != NULL);
assert(interp->runtime->stoptheworld.world_stopped);
ASSERT_WORLD_STOPPED(interp);
return interp->ceval.pending.npending != 0;
}

Expand All @@ -2040,7 +2046,7 @@ interp_has_atexit_callbacks(PyInterpreterState *interp)
{
assert(interp != NULL);
assert(interp->atexit.callbacks != NULL);
assert(interp->runtime->stoptheworld.world_stopped);
ASSERT_WORLD_STOPPED(interp);
assert(PyList_CheckExact(interp->atexit.callbacks));
return PyList_GET_SIZE(interp->atexit.callbacks) != 0;
}
Expand Down Expand Up @@ -2093,7 +2099,7 @@ make_pre_finalization_calls(PyThreadState *tstate)
_PyEval_StartTheWorldAll(interp->runtime);
PyMutex_Unlock(&interp->ceval.pending.mutex);
}
assert(interp->runtime->stoptheworld.world_stopped);
ASSERT_WORLD_STOPPED(interp);
}

static int
Expand Down Expand Up @@ -2130,7 +2136,7 @@ _Py_Finalize(_PyRuntimeState *runtime)
#endif

/* Ensure that remaining threads are detached */
assert(tstate->interp->runtime->stoptheworld.world_stopped);
ASSERT_WORLD_STOPPED(tstate->interp);

/* Remaining daemon threads will be trapped in PyThread_hang_thread
when they attempt to take the GIL (ex: PyEval_RestoreThread()). */
Expand Down
Loading