Zope + Python thread safety
Aahz
aahz at pythoncraft.com
Fri Apr 9 13:30:56 EDT 2004
In article <mailman.440.1080288470.742.python-list at python.org>,
<fowlertrainer at anonym.hu> wrote:
>
>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;
Python is wonderful: readable and usable pseudocode is almost exactly
the same as real Python code:
import threading
lock = threading.RLock()
def ReadVar():
lock.acquire()
Result = GlobalVar
lock.release()
return Result
Note that I'm doing this just to show you how similar it is -- this is
*NOT* how I'd recommend doing it (e.g. poor practice to use a global
variable like that).
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
Why is this newsgroup different from all other newsgroups?
More information about the Python-list
mailing list