Zope + Python thread safety

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fowlertrainer@anonym.hu

    Zope + Python thread safety

    Hello !

    I have been created a Zope (Python) Product.
    But it is must store inner global definitions (some conversion
    parameters), what I need to change in only one thread, or only once.

    See below.

    So: because the Zope is threaded application, the threads are use this
    product. Possible in same time.

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

    In Delphi, or C, with threaded application I must acquire/release a lock, when I
    check/set/read any variable (except integer), like this (pseudo):

    lock=Lock
    func ReadVar():strin g;
    lock.Enter;
    try
    Result:=GlobalV ar;
    finally
    lock.Leave;
    end;

    proc WriteVar(val:st ring);
    lock.Enter;
    try
    GlobalVar:=val;
    finally
    lock.Leave;
    end;

    This way is make the variable using thread-safe, because avoid to
    thread A read while thread B is write (and subsections of the
    information are confusing by another thread).

    My code in python:

    A. version)

    def __init__(self):
    self.Fmts=[['date','%m/%d/%Y'],['time','%H:%M.% S']]
    # default is for hungarian

    def SetConversionFo rmats(self,Fmts ):
    s1=str(Fmts)
    s2=str(self.Fmt s)
    if (s1<>s2)):
    self.Fmts=Fmts

    B. version)

    def __init__(self):
    self.DefFmts=[['date','%Y.%m.% d'],['time','%H:%M.% S']]
    # default is for hungarian
    self.Fmts=None

    def SetConversionFo rmats(self,Fmts ):
    if self.Fmts==None : self.Fmts=Fmts


    Usage:
    updsqlobj=conte xt.updsqlobj()
    updsqlobj.SetCo nversionFormats ([['date','%Y.%m.% d'],['time','%H:%M.% S']],True)
    updsqlobj.Gener ateUpdateSQL(.. )
    updsqlobj.Apply (..)

    The Fmts is a list.

    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.

    Question1:
    The code above is thread safe ? (I think, it is not)
    Question2:
    If it is not thread safe, how to set this variable without global
    lock/mutex object ?
    Question3:
    Or how to I set this object's parameters as property, in Designer
    interface of Zope ?

    Please help me, if possible !

    Thanx for it, and for every advance:

    --
    Best regards,
    fowlertrainer mailto:fowlertr ainer@anonym.hu


Working...