Brain Dead Singleton

Peter Otten __peter__ at
Tue Jun 8 10:07:35 CEST 2004

Robin Becker wrote:

> Peter Hansen wrote:


>> 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

The same is true for modules. If you keep a reference of a module and refer
only to that instead of doing an import every time you need to access your
singleton - well nothing will break that. However, you have now reduced the
original pattern to a mere "please do not rebind that name" convention.


More information about the Python-list mailing list