Skip to content

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