Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f18939a
Initial fix.
ZeroIntensity Nov 10, 2024
756bf41
Remove junk file.
ZeroIntensity Nov 10, 2024
45c4561
Merge branch 'main' of https://github.com/python/cpython into interp-…
ZeroIntensity Nov 10, 2024
a94eaef
Don't overwrite the main thread.
ZeroIntensity Nov 10, 2024
206b581
Small changes.
ZeroIntensity Nov 10, 2024
286e536
Put lock around exception capturing.
ZeroIntensity Nov 10, 2024
2fab7af
Add a comment.
ZeroIntensity Nov 10, 2024
446abc1
Add blurb.
ZeroIntensity Nov 10, 2024
cc36e8d
Add a test.
ZeroIntensity Nov 10, 2024
e25587e
Skip test on the default build.
ZeroIntensity Nov 10, 2024
e4b2c79
Fix and move tests.
ZeroIntensity Nov 10, 2024
aeb483e
Somehow, the locks are re-entrant.
ZeroIntensity Nov 10, 2024
92b3ea7
Don't rely on the interpreter state for _PyXI_ERR_ALREADY_RUNNING
ZeroIntensity Nov 11, 2024
804c41e
Throw an exception if there's a remaining thread state.
ZeroIntensity Nov 11, 2024
2edfda3
Remove newline.
ZeroIntensity Nov 11, 2024
bb8feee
Remove another newline.
ZeroIntensity Nov 11, 2024
5968448
Add docstrings.
ZeroIntensity Nov 11, 2024
9ab979d
Protect _PyIndexPool_AllocIndex with the runtime lock.
ZeroIntensity Nov 11, 2024
b478375
Bump the thread count.
ZeroIntensity Nov 11, 2024
f393ab6
Add comments to the test.
ZeroIntensity Nov 11, 2024
35323f8
Re-enable subinterpreter tests for the free-threaded build.
ZeroIntensity Nov 11, 2024
67df772
Fix tests.
ZeroIntensity Nov 11, 2024
13e96de
Lock runtime instead of using pyatomic
ZeroIntensity Nov 11, 2024
c9e7b08
Fix failing builds.
ZeroIntensity Nov 11, 2024
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 and move tests.
  • Loading branch information
ZeroIntensity committed Nov 10, 2024
commit e4b2c792f8a8ccec915162073cc74fe1f57a5b60
24 changes: 24 additions & 0 deletions Lib/test/test_free_threading/test_interpreters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import threading
import unittest

from test import support
from test.support import import_helper
from test.support import threading_helper
_interpreters = import_helper.import_module('_interpreters')


@threading_helper.requires_working_threading()
class StressTests(unittest.TestCase):

@support.requires_resource('cpu')
def test_subinterpreter_thread_safety(self):
interp = _interpreters.create()
threads = [threading.Thread(target=_interpreters.run_string, args=(interp, "1")) for _ in range(100)]
threads.extend([threading.Thread(target=_interpreters.destroy, args=(interp,)) for _ in range(100)])
with threading_helper.start_threads(threads):
pass


if __name__ == '__main__':
# Test needs to be a package, so we can do relative imports.
unittest.main()
9 changes: 0 additions & 9 deletions Lib/test/test_interpreters/test_stress.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ def task():
with threading_helper.start_threads(threads):
pass

@support.requires_resource('cpu')
@unittest.skipUnless(support.Py_GIL_DISABLED, "the GIL is protecting threads")
def test_subinterpreter_thread_safety(self):
interp = interpreters.create()
threads = [threading.Thread(target=interpreters.run_string, args=(interp,)) for _ in range(100)]
threads.extend([threading.Thread(target=interpreters.destroy, args=(interp,)) for _ in range(100)])
with threading_helper.start_threads(threads):
pass


if __name__ == '__main__':
# Test needs to be a package, so we can do relative imports.
Expand Down
2 changes: 1 addition & 1 deletion Modules/_interpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,14 +723,14 @@ interp_destroy(PyObject *self, PyObject *args, PyObject *kwds)
"interpreter started running during shutdown");
return NULL;
}
#endif

/*
* Running main has now been prevented, the interpreter will
* never run again (GH-126644).
*/
assert(!is_running_main(interp));
assert(!_PyInterpreterState_IsRunningAllowed(interp));
#endif

// Destroy the interpreter.
_PyXI_EndInterpreter(interp, NULL, NULL);
Expand Down
2 changes: 2 additions & 0 deletions Python/crossinterp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,9 @@ void
_PyXI_EndInterpreter(PyInterpreterState *interp,
PyThreadState *tstate, PyThreadState **p_save_tstate)
{
#ifdef Py_GIL_DISABLED
assert(!_PyInterpreterState_IsRunningAllowed(interp));
#endif
#ifndef NDEBUG
long whence = _PyInterpreterState_GetWhence(interp);
#endif
Expand Down