Skip to content

gh-149630: Fix pylifecycle multiple init/fini cleanup bugs #149631

Open
Wulian233 wants to merge 1 commit intopython:mainfrom
Wulian233:fix-multiple-init/fini-cleanup-bugs
Open

gh-149630: Fix pylifecycle multiple init/fini cleanup bugs #149631
Wulian233 wants to merge 1 commit intopython:mainfrom
Wulian233:fix-multiple-init/fini-cleanup-bugs

Conversation

@Wulian233
Copy link
Copy Markdown
Contributor

@Wulian233 Wulian233 commented May 10, 2026

Fix multiple resource-management and error-path bugs in the interpreter lifecycle.

Release the builtins module reference on builtin initialization failures and keep it owned until default import initialization succeeds, avoiding an extra NULL assignment. Also DECREF results from non-dict sys.modules clear calls, route subinterpreter initialization failures through cleanup after thread-state detach, release __main__ setup references on PyDict_SetItemString failures, and check stdin/stdout sys object setup failures consistently with stderr.

Tests run:

- ./configure --with-pydebug

- git diff --check

- make -j2 Python/pylifecycle.o

- make -j2 python Programs/_testembed

- make -j2

- Programs/_testembed test_repeated_init_and_subinterpreters

- ./python - <<'PY'
import _interpreters
interp = _interpreters.create()
_interpreters.destroy(interp)
print('ok')
PY

- make patchcheck (fails because this checkout has no upstream remote matching https://github.com/python/cpython)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant