Skip to content

bpo-46417: Py_Finalize() clears static types #30743

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

Merged
merged 1 commit into from
Jan 21, 2022
Merged

bpo-46417: Py_Finalize() clears static types #30743

merged 1 commit into from
Jan 21, 2022

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jan 21, 2022

Add _PyTypes_FiniTypes(): best-effort function to clear static types,
don't deallocate a type if it still has subclasses.

remove_subclass() now sets tp_subclasses to NULL when removing the
last subclass.

https://bugs.python.org/issue46417

Add _PyTypes_FiniTypes(): best-effort function to clear static types,
don't deallocate a type if it still has subclasses.

remove_subclass() now sets tp_subclasses to NULL when removing the
last subclass.
@vstinner
Copy link
Member Author

Using PR #30744, the effect of this PR is quite clear on the total reference count after Py_Finalize():

  • Before (main branch): [10120 refs, 3740 blocks]
  • After (this PR): [4801 refs, 1926 blocks]

This PR removes 5319 references. With the PR, there are 2.1x less references leaked after Py_Finalize()!

@vstinner
Copy link
Member Author

_PyTypes_FiniTypes() is tested (indirectly) by multiple test_embed tests which use many of the cleared types after Py_Finalize().

@vstinner vstinner merged commit 595225e into python:main Jan 21, 2022
@vstinner vstinner deleted the fini_types branch January 21, 2022 12:06
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot s390x Debian 3.x has failed when building commit 595225e.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/49/builds/1789) and take a look at the build logs.
  4. Check if the failure is related to this commit (595225e) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/49/builds/1789

Failed tests:

  • test_unittest

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/dje/cpython-buildarea/3.x.edelsohn-debian-z/build/Lib/multiprocessing/resource_tracker.py", line 209, in main
    cache[rtype].remove(name)
    ^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: '/psm_b32ae02e'


Traceback (most recent call last):
  File "/home/dje/cpython-buildarea/3.x.edelsohn-debian-z/build/Lib/multiprocessing/resource_tracker.py", line 209, in main
    cache[rtype].remove(name)
    ^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: '/psm_bb4f5e76'

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.

3 participants