By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,539 Members | 1,289 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,539 IT Pros & Developers. It's quick & easy.

Zope + Python thread safety

P: n/a
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():string;
lock.Enter;
try
Result:=GlobalVar;
finally
lock.Leave;
end;

proc WriteVar(val:string);
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 SetConversionFormats(self,Fmts):
s1=str(Fmts)
s2=str(self.Fmts)
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 SetConversionFormats(self,Fmts):
if self.Fmts==None: self.Fmts=Fmts
Usage:
updsqlobj=context.updsqlobj()
updsqlobj.SetConversionFormats([['date','%Y.%m.%d'],['time','%H:%M.%S']],True)
updsqlobj.GenerateUpdateSQL(..)
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:fo***********@anonym.hu
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.