{"body":"import sys\nimport gc\nimport weakref\n\nclass A:\n    pass\n\ndef other(a):\n    v = []  # using a list rather than nonlocal for pypy2 support\n\n    # delete the only remaining ref to a and replace with a weakref\n    a = weakref.ref(a, lambda _: v.append(True))\n    while not v:\n        # on cpython this branch is never hit, but on pypy we need to sit and\n        # collect, until the object is deleted\n        gc.collect()\n\n\ndef main():\n    # move our reference to the instance of A into other\n    other(*(A(), ))\n\nif __name__ == \"__main__\":\n    sys.exit(main())","name":"demo.py","extension":"py","url":"https://www.irccloud.com/pastebin/11FrLMyJ/demo.py","modified":1729610770,"id":"11FrLMyJ","size":556,"lines":24,"own_paste":false,"theme":"","date":1729610770}