[Python-Dev] try/except in io.py (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Fri Dec 19 14:50:37 CET 2008
- Previous message: [Python-Dev] try/except in io.py
- Next message: [Python-Dev] try/except in io.py
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-Dev] try/except in io.py
- Next message: [Python-Dev] try/except in io.py
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]