Skip to content

gh-129185: Simplify PyTraceMalloc_Track()#129256

Merged
vstinner merged 1 commit intopython:mainfrom
vstinner:tracemalloc_fini
Jan 24, 2025
Merged

gh-129185: Simplify PyTraceMalloc_Track()#129256
vstinner merged 1 commit intopython:mainfrom
vstinner:tracemalloc_fini

Conversation

@vstinner
Copy link
Copy Markdown
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
Copy Markdown
Member Author

cc @ZeroIntensity

Copy link
Copy Markdown
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
@vstinner vstinner deleted the tracemalloc_fini branch January 24, 2025 13:29
@vstinner
Copy link
Copy Markdown
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
Copy Markdown
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