Brain Dead Singleton
robin at SPAMREMOVEjessikat.fsnet.co.uk
Tue Jun 8 00:50:49 CEST 2004
Peter Hansen wrote:
>> The docs for 2.3 say
>> This is a dictionary that maps module names to modules which have
>> already been loaded. This can be manipulated to force reloading of
>> modules and other tricks.... "
> Hmmm... I'd be more inclined to think it was an approval
> if it didn't use the term "trick" to describe it.
> Anyway, this now leads me to wonder whether any singleton
> pattern which doesn't involve manipulating __builtin__ is
> safe from deletion of items in sys.modules...
If you hold onto an instance then I think it's safe, I guess the problem
is when the class code (from a module) gets violently changed in some
way. When you next get an instance even from a borg type pattern it
needn't be the same as the last instance. Of course modules, classes etc
are not normally read only so they can be subverted just by writing into
More information about the Python-list