Why do I get different instances of the same singleton in different modules?

The reason you get two singletons is due to the way the modules are being imported. When you execute test.py from the command line, it is not known as test it is main . An entry is added to sys.

Modules under the name main and execution proceeds. When untitled imports test sys. Modules is examined, no module named test is found, so test.py is executed again to import it.

As a result, the class definition for A is executed twice, producing two distinct classes. The Singleton implementation therefore considers them distinct, and produces two instances.

I don't know why do you need singletons for, but just taking a look at that "singleton mixin" you pointed too reminded me of an old joke chain-email showing the various stages of a programer (d)evolution, with various examples of a hello world program. On that e-mail, the low-point was the "enterprise class senior program" which developed a client server system, implementing various patterns, in order to write ".

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions