[Zope] Zope + Python thread safety

Chris Withers lists at simplistix.co.uk
Fri Mar 26 06:15:20 EST 2004


fowlertrainer at anonym.hu wrote:

> Question: the python variable setting/checking is thread-safe ?

Python has Lock objects just like Delphi and C, I'd wrap your setting/checking 
code in the same way as you would for Delphi/C...

> I want to set the parameters of Product in only once, but because the
> Zope is threaded app, I must thinking in thread-safe programming methods.

Indeed, Zope and ZODb usually take care of all of this for you, but you're doing 
something out of the ordinary, so need to worry aboutit ...

> Question1:
>   The code above is thread safe ? (I think, it is not)

No.

> Question2:
>   If it is not thread safe, how to set this variable without global
>   lock/mutex object ?

You need to put a lock around those bits of code.

> Question3:
>   Or how to I set this object's parameters as property, in Designer
>   interface of Zope ?

I'd just have them as Zope Properties on your container object, then you don't 
need to worry about the threading.

context.manage_addProperty('prop name','value','string')

...for example.

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk




More information about the Zope mailing list