[Python-Dev] Problem between deallocation of modules and func_globals (original) (raw)
Brett Cannon brett at python.org
Sat Jan 20 00:01:42 CET 2007
- Previous message: [Python-Dev] Problem between deallocation of modules and func_globals
- Next message: [Python-Dev] Problem between deallocation of modules and func_globals
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 1/19/07, M.-A. Lemburg <mal at egenix.com> wrote:
On 2007-01-19 22:33, Brett Cannon wrote: >> That's a typical error situation you get in del methods at >> the time the interpreter is shut down. >> > > Yeah, but in this case this is at the end of PyInitialize() for the > stuff I am doing to the interpreter. =)
Is that in some error branch of PyInitialize() ? Otherwise I don't see how the modules could get garbage-collected.
Nope, it's code I am adding to clean out sys.modules of stuff the user didn't import themselves; it's for security reasons.
>> I'm not exactly sure which global state you are referring to. The >> aliase map, the cache used by the search function ? >> > > encodings.cache . > >> Note that the search function registry is a global managed >> in the thread state (it's not stored in any module). >> > > Right, but that is not the issue. If you have deleted the reference > to the encodings module from sys.modules it then sets encodings.cache > to None. After the deletion, if you try to encode/decode a unicode > string you can an AttributeError about how encodings.cache does not > have a 'get' method since it is now None instead of a dict. The > function is fine and still runs, it's just that the global state it > depends on is no longer the way it assume it should be.
While I could add some tricks to have the cache dictionary stay alive even after the globals were set to None, I doubt that this will really fix the problem. The encoding package relies on the import mechanism, the codecs module and the codecs builtin module. Any of these could fail to work depending on the order in which the modules get GCed. There's a reason why things in PyFinalize() are as carefully ordered :-) Perhaps we need to apply some reordering to the steps in PyInitialize() ?!
Nah, I just need to not delete the modules. =)
-Brett
- Previous message: [Python-Dev] Problem between deallocation of modules and func_globals
- Next message: [Python-Dev] Problem between deallocation of modules and func_globals
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]