A few months ago, #8023 added some details to the docs about how Py_RunMain determines its exit status. Specifically, it wrote thatPy_RunMain exits the process on an unhandled SystemExit.
But this isn't the case, at least not when running via the pymain_run_module path (the other paths aren't so clear to me). The relevant code is in pymain_err_print, which specifically checks for SystemExit in order to avoid passing it to PyErr_Print, which is where exit would actually be called.
My understanding is that Py_RunMain was intended for an embedded context, in which case exiting the process is probably not desirable.
The docs of Py_Main have specified the process exiting behavior for much longer, but right now it looks like both functions share the same implementation.
@vstinner @ncoghlan
Linked PRs
A few months ago, #8023 added some details to the docs about how
Py_RunMaindetermines its exit status. Specifically, it wrote thatPy_RunMainexits the process on an unhandledSystemExit.But this isn't the case, at least not when running via the
pymain_run_modulepath (the other paths aren't so clear to me). The relevant code is inpymain_err_print, which specifically checks forSystemExitin order to avoid passing it toPyErr_Print, which is whereexitwould actually be called.My understanding is that
Py_RunMainwas intended for an embedded context, in which case exiting the process is probably not desirable.The docs of
Py_Mainhave specified the process exiting behavior for much longer, but right now it looks like both functions share the same implementation.@vstinner @ncoghlan
Linked PRs