[Zope-dev] thread safety in external methods

Jim Fulton jim@digicool.com
Thu, 02 Sep 1999 09:01:22 -0400


Michel Pelletier wrote:
> 
> Robin Becker wrote:
> >
> > 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.
> >
> 
> When Zope starts up it imports all the modules containing external
> methods.

No it doesn't. It imports products at startup. It *loads* external
methods when it needs to.

Jim

--
Jim Fulton           mailto:jim@digicool.com   Python Powered!        
Technical Director   (888) 344-4332            http://www.python.org  
Digital Creations    http://www.digicool.com   http://www.zope.org    

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.