[pypy-issue] Issue #2612: gc.get_referrers doesn't always find instance of referrer class (pypy/pypy)

Daniel Sutcliffe issues-reply at bitbucket.org
Fri Jul 21 05:51:14 EDT 2017

New issue 2612: gc.get_referrers doesn't always find instance of referrer class

Daniel Sutcliffe:

This problem is intermittent in that in can come and go away with code structure but when code is unchanged results are repeatable.

Reproduced using official Docker pypy container and using squeaky-pl's portable PyPy with version 5.8.0 build for Python 2.7.13.

Actually initially found trying to get Twisted test suite passing under PyPy where the twisted.test.test_rebuild.RebuildTests.testFileRebuild FAILs but included is the smallest bit of code I have managed to get this to fail under. Two files required as problem doesn't seem to occur with class in `__main__`  
class B(object):
    def m(self):
        return 'b1'
import BC
import gc
b = BC.B()
# Doesn't find
for r in gc.get_referrers(BC.B):
    if getattr(r, '__class__', None) is BC.B:
        print('get_referrers finds {0}'.format(r))
# Finds
for r in gc.get_objects():
    if getattr(r, '__class__', None) is BC.B:
        print('get_objects finds {0}'.format(r))
The last 4 lines just there to show get_objects always seems to work - used as workaround in my Twisted fork.

As stated, I have seen `gc.get_referrers` many times return the correct result, often just prior to including one more line of code before the call so this is obviously something a little weird - hope the issue is not too difficult to reproduce and find with this info, I must admit to having not looked at PyPy gc code


More information about the pypy-issue mailing list