Design thought for callbacks

Chris Angelico rosuav at gmail.com
Sun Feb 22 06:14:34 EST 2015


On Sun, Feb 22, 2015 at 9:32 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Why? Do you expect that the Python garbage collector special cases callbacks
> to keep them alive even when there are no references to them? How would it
> distinguish a callback from some other function?

No no no. It's the other way around. _Something_ has to be doing those
callbacks, and it's that _something_ that should be keeping them
alive. The fact that it's a registered callback should itself *be* a
reference (and not a weak reference), and should keep it alive.

ChrisA



More information about the Python-list mailing list