Brain Dead Singleton

Peter Hansen peter at
Tue Jun 8 00:11:46 CEST 2004

Robin Becker wrote:
> Peter Hansen wrote:
>> I don't think deleting things from
>> sys.modules has defined, guaranteed behaviour, so I'm uncertain
>> whether anyone should rely on it working.  
> If sys.modules isn't intended to be a modifiable cache, perhaps we 
> shouldn't be given access to it.
> The docs for 2.3 say
> "modules
>     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...


More information about the Python-list mailing list