You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
free-threading GC does not properly track references to a running function #160682
deftest_running_method_not_collected(self):
# The class dict holds the only counted reference to the method.# The running frame's deferred reference must keep it alive.classC:
defm(self):
wr=weakref.ref(C.__dict__['m'])
delC.mgc.collect()
returnwr() isnotNonedefrun(self):
returnself.m()
self.assertTrue(C().run())
In the above gc.collect() cleans up C.m however m is still running in an instance so should not be cleaned up. The above is a bit of a contrived example but it shows the gap reliably.
In a more real world example this could show up in more common code with monkey patching, importlib.reload, repls. It should be a small fix to ensure frame->f_funcobj is properly accounted for in free threading GC.
changed the title [-]free-threading GC does properly track references to a running function[/-][+]free-threading GC does not properly track references to a running function[/+]on Oct 26, 2026
Activity
[-]free-threading GC does properly track references to a running function[/-][+]free-threading GC does not properly track references to a running function[/+]pythongh-160682: Add NEWS entry
pythongh-160682: Fix NEWS entry filename
gh-160682: Track running function objects in free-threaded GC (#160707)