Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-109047: Add PythonFinalizationError exception#109809
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
vstinner commented Sep 24, 2023 • edited by github-actions bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by github-actions bot
Uh oh!
There was an error while loading. Please reload this page.
vstinner commented Sep 24, 2023
Ubuntu failed (logs reformatted): |
Add PythonFinalizationError. This exception derived from RuntimeError is raised when an operation is blocked during the Python finalization. The following functions now raise PythonFinalizationError, instead of RuntimeError: * _thread.start_new_thread() * os.fork() * os.fork1() * os.forkpty() Morever, _winapi.Overlapped finalizer now logs an unraisable PythonFinalizationError, instead of an unraisable RuntimeError.
261082a to 6d969f3CompareAA-Turner commented Sep 25, 2023
Perhaps drop the 'Python' prefix (or perhaps change to IntepreterFinalizationError etc) -- as a reader, I'd be confused as to what Python is trying to signify in the name. A |
vstinner commented Sep 25, 2023
Python can have multiple interpreters. This exception is when the main interpreter is being finalized. I prefer to document it as "Python finalization". If it's called FinalizationError, you may ask: which finalization? All Python objects have finalizers. |
AA-Turner commented Sep 25, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
PrimaryIntepreterFinalizationError? It's perhaps getting a bit silly, though. I still think that 'PythonFinalizationError' is unclear--for example as you noted I would naively think that it would apply to e.g. subinterpreter finalisation, as that's still part of Python. Whilst FinalizationError is generic (as you say), that might not be a bad thing, in case custom object finalisers need to raise errors of a similar nature as here? A |
vstinner commented Sep 25, 2023
I prefer the term "Python finalization error".
What is being finalized is not a sub-interpreter or the main interpeter, but in fact, it's the world "Python world": anything related to Python. It's wider than the main interpreter. There are many "global variables" cross-interprereters. Like path configuration (_PyPathConfig_ClearGlobal()), runtime (_PyRuntime_Finalize()), etc. For example, before, Py_Initialize(), it's not possible to create a Python object. Py_Finalize() destroys ("finalizes") all Python objects. When Py_Finalize() completes, it's no longer possible to create new Python objects. That's why https://docs.python.org/dev/c-api/init.html and https://docs.python.org/dev/c-api/init_config.html#init-config are about "Python Initialization". Sadly, https://docs.python.org/dev/c-api/init.html#c.Py_FinalizeEx is not well documented. https://docs.python.org/dev/library/sys.html#sys.is_finalizing mentions "the main Python interpreter". I'm not happy about https://docs.python.org/dev/glossary.html#term-interpreter-shutdown glossary entry. It isn't clear if we are talking about the main interpreter, a sub-interpreter, or "Python". Moreover, there is a competition between "shutting down" and "finalization" terms in the documentation. It should be unified. "Finalization" term is part of the public API: sys.is_finalizing() and Py_Finalize(). "Shutdown" is used in one private API: threading._shutdown(). My notes of Python finalization: https://pythondev.readthedocs.io/finalization.html |
vstinner commented Sep 29, 2023
My fix PR gh-109810 does not strictly need a new exception. So close this PR for now, until someone comes with a more concrete use case which requires adding a new exception. |
vstinner commented Feb 12, 2024
I created a new PR for this exception: #115352 |
Add PythonFinalizationError. This exception derived from RuntimeError is raised when an operation is blocked during the Python finalization.
The following functions now raise PythonFinalizationError, instead of RuntimeError:
Morever, _winapi.Overlapped finalizer now logs an unraisable PythonFinalizationError, instead of an unraisable RuntimeError.
📚 Documentation preview 📚: https://cpython-previews--109809.org.readthedocs.build/