This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Py_RunMain() crashes on subsequence call
Type: crash Stage: resolved
Components: C API Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: indygreg, iritkatriel, lukasz.langa, miss-islington, vstinner
Priority: normal Keywords:

Created on 2020-04-28 01:54 by indygreg, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patch vstinner, 2021-09-20 07:42
Pull Requests
URL Status Linked Edit
PR 28466 merged vstinner, 2021-09-20 07:41
PR 28470 merged miss-islington, 2021-09-20 08:30
PR 28471 merged miss-islington, 2021-09-20 08:30
Messages (9)
msg367479 - (view) Author: Gregory Szorc (indygreg) * Date: 2020-04-28 01:54
I'm attempting to perform the following actions multiple times in a single process with CPython 3.8.2:

1) Initialize an interpreter using the PEP-587 APIs.
2) Call Py_RunMain() (which finalizes the interpreter).

However, I've encountered at least 2 crashes due to use-after-free or unchecked NULL access (due to apparent state getting funky).

Are multiple interpreters / Py_RunMain() calls in a single process supported? Should I file bugs for all of the crashes I encounter?
msg367480 - (view) Author: Gregory Szorc (indygreg) * Date: 2020-04-28 02:01
Actually, I can reproduce the crash without Py_RunMain(). So I don't think the crash is related to the additional cleanup that Py_RunMain() does in addition to Py_FinalizeEx().

But I'd like to keep this issue open to track the original question about expected behavior.
msg367526 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-04-28 12:46
I never tried, but I expect that the following pattern is fine:

for (i=0; i<5; i++) {
    Py_Initialize(); Py_RunMain()
}

Maybe Py_RunMain() must fail with a fatal error if it's called when Python is not initialized.

Since Py_RunMain() finalizes Python, you cannot call it multiple times without calling Py_Initialize() between calls.
msg402174 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-09-19 22:09
Is there anything to do on this issue? Gregory, perhaps you could report the crashes you see so they can be evaluated?
msg402203 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-09-20 07:42
> I'm attempting to perform the following actions multiple times in a single process with CPython 3.8.2:

test_embed already has test_repeated_init_and_inittab() test which runs Py_InitializeFromConfig() + Py_RunMain() multiple times.

I wrote an even more explicit test in PR 28466. I tested it manually on Python 3.9, 3.10 and 3.11: it works as expected.

Python 3.8 no longer accepts bugfixes. I close the issue as outdated.

Gregory: if you can still reproduce your issue on a supported Python version, please provide a reproducer.
devguide.python.org/#status-of-python-branches
msg402213 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-09-20 08:30
New changeset 5e2c32e08ed77081cabd9d51f0589f81c1572732 by Victor Stinner in branch 'main':
bpo-40413: test_embed tests calling Py_RunMain() multiple times (GH-28466)
https://github.com/python/cpython/commit/5e2c32e08ed77081cabd9d51f0589f81c1572732
msg402215 - (view) Author: miss-islington (miss-islington) Date: 2021-09-20 08:48
New changeset 3d16fc90ce36acaa846ee88bdd124f84d49395b3 by Miss Islington (bot) in branch '3.10':
bpo-40413: test_embed tests calling Py_RunMain() multiple times (GH-28466)
https://github.com/python/cpython/commit/3d16fc90ce36acaa846ee88bdd124f84d49395b3
msg402249 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-20 15:51
New changeset 29e431419a0c23340099a9cd8cf23ec9c7788879 by Miss Islington (bot) in branch '3.9':
bpo-40413: test_embed tests calling Py_RunMain() multiple times (GH-28466) (GH-28471)
https://github.com/python/cpython/commit/29e431419a0c23340099a9cd8cf23ec9c7788879
msg403882 - (view) Author: Gregory Szorc (indygreg) * Date: 2021-10-14 02:36
I can't remember the circumstances of me reproducing this. The added test demonstrating that the interpreter can be initialized/finalized within a single process seems like a reasonable solution to ensure this is supported.
History
Date User Action Args
2022-04-11 14:59:30adminsetgithub: 84593
2021-10-14 02:36:21indygregsetmessages: + msg403882
2021-09-20 15:51:40lukasz.langasetnosy: + lukasz.langa
messages: + msg402249
2021-09-20 08:48:05miss-islingtonsetmessages: + msg402215
2021-09-20 08:30:22miss-islingtonsetpull_requests: + pull_request26870
2021-09-20 08:30:15miss-islingtonsetnosy: + miss-islington

pull_requests: + pull_request26869
2021-09-20 08:30:06vstinnersetmessages: + msg402213
2021-09-20 07:42:00vstinnersetstatus: open -> closed
files: + patch
messages: + msg402203

resolution: out of date
stage: resolved
2021-09-20 07:41:00vstinnersetstatus: pending -> open
pull_requests: + pull_request26865
2021-09-19 22:09:51iritkatrielsetstatus: open -> pending
nosy: + iritkatriel
messages: + msg402174

2020-04-28 12:46:11vstinnersetmessages: + msg367526
2020-04-28 02:01:32indygregsetmessages: + msg367480
2020-04-28 01:54:31indygregcreate