-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
Leaks on Python's standard library at runtime shutdown #100911
Comments
cc @vstinner |
It will work as expected once more extensions will be converted to the multi-phase initialization API. Recent work by @erlend-aasland: commit fee7a99. |
Do you have a list of extension modules that leak at shutdown? |
When I modified Python to clear static types and static exceptions, I wrote a patch to list types and exceptions which cannot be deallocated because there are still referenced somehow: In that list, you can see some C extension names:
Some C extensions are already converted to heap types and multi-phase initialization. But this list is not easy to use: you have to identify to "root objects" which keeps all other objects alive indirectly. For example, the _io module still uses static types. |
Problem
Wanted to surface a couple of existing leaks in the standard library that happen at runtime shutdown. Simple statements like
import unittest
orimport itertools
already trigger these leaks. In general, these make it much harder to guarantee a correct shutdown, specially in cases where we want to explicitly clean up the entire allocated memory space before the runtime gets reinitialized (i.e in embedded applications).Repro
Build on debug mode:
By default, the runtime and various imports do not leak:
However, a good chunk of imports in the standard library leak. Examples of these include:
argparse
,itertools
, etc. Example:Future Prevention
While each of these leaks has to be addressed on its own (and this bug report does not contain a proposed fix), there should probably add stronger guarantees that at least the core runtime and its standard library will not leak. This could start with a test that goes through all imports and guarantees that they won't leak and it can already start with an allowlist of the various libraries that do not leak.
The text was updated successfully, but these errors were encountered: