Kristján Valur Jónsson wrote: > Ah, but that is not what the intent is to guard agains, according the > comments. During exit, modules have been deleted and all sorts of > things have gone away. It is therefore likely that code that executes > during exit will encounter NameErrors (when a module is being cleaned > up and its globals removed) And AttributeErrors. ImportErrors too, in > fact. > > It would be good to see the actual repro case that caused this to be > added in the first place, so that we could selectively catch those > errors.
Generally speaking, close() and __delete__() methods that can be invoked during interpreter shutdown should avoid referencing module globals at all. Necessary globals (including members of other modules) should either be cached on the relevant class or captured in a closure. Now, it may be that the relevant close() method in io.py touches too much code for that to be practical, but it certainly isn't the case in general that encountering Name/Attribute/ImportError during shutdown is inevitable. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia --------------------------------------------------------------- _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com