Skip to content

gh-129185: Simplify PyTraceMalloc_Track() #129256

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 24, 2025

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jan 24, 2025

Since tracemalloc uses PyMutex, it becomes safe to use TABLES_LOCK() even after _PyTraceMalloc_Fini(): remove the "pre-check" in PyTraceMalloc_Track() and PyTraceMalloc_Untrack().

PyTraceMalloc_Untrack() no longer needs to acquire the GIL.

_PyTraceMalloc_Fini() can be called earlier during Python finalization.

Since tracemalloc uses PyMutex, it becomes safe to use TABLES_LOCK()
even after _PyTraceMalloc_Fini(): remove the "pre-check" in
PyTraceMalloc_Track() and PyTraceMalloc_Untrack().

PyTraceMalloc_Untrack() no longer needs to acquire the GIL.

_PyTraceMalloc_Fini() can be called earlier during Python
finalization.
@vstinner
Copy link
Member Author

cc @ZeroIntensity

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but it might be worth deleting the blurb entry from the other PR.

@vstinner vstinner merged commit fc6bc1e into python:main Jan 24, 2025
44 checks passed
@vstinner vstinner deleted the tracemalloc_fini branch January 24, 2025 13:29
@vstinner
Copy link
Member Author

but it might be worth deleting the blurb entry from the other PR.

Recently, I only added a single NEWS entry:

gh-128679: tracemalloc: Fix race conditions when tracemalloc.stop() is called by a thread, while other threads are tracing memory allocations. Patch by Victor Stinner.

This NEWS entry remains relevant.

@ZeroIntensity
Copy link
Member

Ok, I thought you had added one for #129191. My bad!

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.

2 participants