[Python-Dev] Cycle collection enhancement idea (original) (raw)

eyal.lotem+pyutils@gmail.com eyal.lotem at gmail.com
Sun Jun 29 13:26:08 CEST 2008


On Jun 28, 6:21 pm, Nick Coghlan <ncogh... at gmail.com> wrote:

Eyal Lotem wrote: > Example:

> import os > class RunningFile(object): >     filename = '/tmp/running' >     def init(self): >         open(self.filename, 'wb') >     def del(self): >         os.unlink(self.filename) > runningfile = RunningFile() > The deller object is in a cycle as described above [as well as the > Deller class itself].  When Python exits, it could call > deller.del() and then collect the cycle. But Python does the wrong > thing here, and gets rid of the globals before calling del: > Exception exceptions.AttributeError: "'NoneType' object has no > attribute 'unlink'" in <_main_.RunningFile object at 0x7f9655eb92d0>> ignored I don't know what you're trying to get at with this example. There isn't any cyclic GC involved at all, just referencing counting. And before the module globals are cleared, runningfile is still referenced, so calling its del method early would be an outright error in the interpreter (as far as I know, getting del methods to run is one of the reasons for clearing the module globals). It's a fact of Python development: del methods cannot safely reference module globals, because those globals may be gone by the time that method is invoked. That's because globals are being cleaned up in an ad-hoc manner, instead of just using cyclic GC that supports cycles.

Cheers, Nick. -- Nick Coghlan   |   ncogh... at gmail.com   |   Brisbane, Australia ---------------------------------------------------------------  http://www.boredomandlaziness.org


Python-Dev mailing list Python-... at python.orghttp://mail.python.org/mailman/listinfo/python-dev Unsubscribe:http://mail.python.org/mailman/options/python-dev/python-dev2-garchiv...



More information about the Python-Dev mailing list