8000 gh-120838: Add Tests For "Bad" Usage in Runtime Lifecycle Operations by ericsnowcurrently · Pull Request #120840 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-120838: Add Tests For "Bad" Usage in Runtime Lifecycle Operations #120840

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4e8a976
Add the option to not reuse the initial tstate.
ericsnowcurrently Jun 20, 2024
120c2a6
Add a test to verify the initial "main" tstate isn't special.
ericsnowcurrently Jun 20, 2024
608139b
Add tests to check different "bad" runtime fini situations.
ericsnowcurrently Jun 20, 2024
592b214
Fix the code in test_audit_subinterpreter.
ericsnowcurrently Jun 20, 2024
e6f31ff
Always try reusing the main tstate (and drop interp.reuse_init_tstate).
ericsnowcurrently Jun 21, 2024
05c0cf3
Skip test_fini_in_subthread on Windows.
ericsnowcurrently Jun 25, 2024
8b241d2
Expect a failure on Windows.
ericsnowcurrently Jun 25, 2024
b66c2b7
Fail if PyFinalize() fails.
ericsnowcurrently Jun 25, 2024
88b1679
Add _Py_Finalize() and struct pyfinalize_args.
ericsnowcurrently Jun 20, 2024
d9d0e10
Use _Py_Finalize() in the new tests.
ericsnowcurrently Jun 21, 2024
72e961f
Factor out resolve_final_tstate().
ericsnowcurrently Jun 25, 2024
e2392c2
Fix the Windows returncode.
ericsnowcurrently Jun 25, 2024
6b1eb57
Export _Py_Finalize().
ericsnowcurrently Jun 25, 2024
7b2afb6
Do not print the error messages with Py_Exit().
ericsnowcurrently Jun 25, 2024
155dddc
Rename the macro.
ericsnowcurrently Jun 25, 2024
f37bcc7
Fix the macro.
ericsnowcurrently Jun 25, 2024
0cffd32
Merge branch 'main' into tests-runtime-lifecycle-bad-usage
ericsnowcurrently Jun 26, 2024
361d477
Fix tests.
ericsnowcurrently Jun 26, 2024
d3beea4
Tweaks to resolve_final_tstate().
ericsnowcurrently Jun 27, 2024
d78f655
Fix the test failures.
ericsnowcurrently Jun 27, 2024
e5c5a5f
More tweaking resolve_final_tstate().
ericsnowcurrently Jun 27, 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 the macro.
  • Loading branch information
ericsnowcurrently committed Jun 25, 2024
commit f37bcc76405e349ee6ea580d4c70e7756351cb1f
12 changes: 6 additions & 6 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1920,13 +1920,13 @@ finalize_interp_delete(PyInterpreterState *interp)
static PyThreadState *
resolve_final_tstate(_PyRuntimeState *runtime, struct pyfinalize_args *args)
{
#define HANDLE_ERROR(msg) \
#define PRINT_ERROR(msg) \
if (args->verbose) { \
fprintf(stderr, "%s: %s\n", args->caller, msg); \
}

if (!_Py_IsMainThread()) {
HANDLE_ERROR("expected to be in the main thread");
PRINT_ERROR("expected to be in the main thread");
}

PyThreadState *tstate = _PyThreadState_GET();
Expand All @@ -1935,19 +1935,19 @@ resolve_final_tstate(_PyRuntimeState *runtime, struct pyfinalize_args *args)
PyInterpreterState *main_interp = _PyInterpreterState_Main();

if (tstate->interp != main_interp) {
HANDLE_ERROR("expected main interpreter to be active");
PRINT_ERROR("expected main interpreter to be active");
}

/* The main tstate is set by Py_Initialize(), but can be unset
* or even replaced in unlikely cases. */
PyThreadState *main_tstate = runtime->main_tstate;
if (main_tstate == NULL) {
HANDLE_ERROR("main thread state not set");
PRINT_ERROR("main thread state not set");
}
else if (tstate != main_tstate) {
/* Code running in the main thread could swap out the main tstate,
which ends up being a headache. */
HANDLE_ERROR("using different thread state than Py_Initialize()");
PRINT_ERROR("using different thread state than Py_Initialize()");
}
else {
assert(main_tstate->interp != NULL);
Expand All @@ -1956,7 +1956,7 @@ resolve_final_tstate(_PyRuntimeState *runtime, struct pyfinalize_args *args)

return tstate;

#undef ERROR
#undef PRINT_ERROR
}

int
Expand Down
Loading
0