[Zope-dev] thread safety in external methods

Robin Becker robin@jessikat.demon.co.uk
Fri, 20 Aug 1999 12:02:07 +0100


How do I do thread safety inside an External method.

I want to access a global singleton as

def __ZGA():
    if not hasattr(sys.modules['__main__'],'__ZGA'):
        #unsafe here...
        Z=ZGA_calculator()
        # initialise things to do with Z
        sys.modules['__main__'].__dict__['__ZGA']=Z
    return sys.modules['__main__'].__dict__['__ZGA']

the problem is controlling access to sys.modules['__main__'].__dict__['__ZGA']. I can't have a
global lock inside my external method as I get a different environment with each call (which is
why I need the singleton in the first place).

It would be sufficient for my purposes if I could guarantee to get certain code run just once
at startup time.

Do I have to make a product or is there some easier way to do this.
-- 
Robin Becker