Problem with using singleton receip in python

Vineet Jain vineet at eswap.com
Thu Apr 8 19:52:36 EDT 2004


I started off doing the following:


Class someClass(Singleton):

This worked fine but was not elegant. I'm using a large number of Singleton
classes. And Having to create a new object and discard it millions of times
added up. My functions get called many many times.

So I decided to use a GlobalMadules class which has all my global classes
and resources. I initialize this at the begining of my program.

The problem is that in the main program I have to do:

from GlobalModules import initGlobalModule
from GlobalModules.someGlobalClass import someGlobalClass

def someFunction:
	initGlobalModule()
	someGlobalClass.conn(qry)

does not work since someGlobalClass has not been initialized, so I have to
do the following:

def someFunction:
	initGlobalModule()

	from GlobalModules.someGlobalClass import someGlobalClass
someGlobalClass.conn(qry)

Somehow I like all my import at the top of the file and this does not seem
right. Is there some other way to do this?

Thanks,






More information about the Python-list mailing list