Brain Dead Singleton

Peter Hansen peter at engcorp.com
Sat Jun 5 07:36:46 EDT 2004


Robin Becker wrote:

> Colin Brown wrote:
>> Whenever I want a singleton "class", I just use a module with 
>> functions and
>> global variables. Modules only import once.
>>
> should often work, but this illustrates how it can go wrong
[...]
> del sys.modules['my_singleton_module']
[...]
> so if sys.modules gets interfered with approriately, your singleton can 
> start breeding.

We're all adults.  How often do you see (or write) code that
goes around deleting modules from sys.modules.  Colin's
suggesting is just fine for most sane situations.

-Peter



More information about the Python-list mailing list