Closed pteromys closed 11 months ago
Oh, I like that idea. Done! Let's see if it breaks anything...
There turned out to be another cycle -- protocol -> transport -> protocol
-- which doesn't seem to get broken on the transport side in a Proactor loop on Windows.
Thanks for following up and fixing that! (Sorry, I should've said something right away when I saw the test failure on Windows and realized it was going to be over my head!)
A bound method contains a reference to the instance it's bound to. Most of the time, bound methods are created lazily at access time by the descriptor protocol and discarded after calling. But saving a bound method as another attribute on the instance creates a long-lived cycle, here
.timeout_callback.__self__
, that needs to be explicitly broken if we don't want to wake up python's garbage collector to do it.Without this change, the new assertion in the tests would fail, and
pytest --pdb
would show the bound methods_on_timeout
and_on_waiter_completed
at the end ofp gc.get_referrers(protoref())
.Things I'm not too certain about:
.timeout_callback
and.completed_callback
—I empirically seem to have covered my use case, but that's far from actually understanding what gets called when