On Sep 5, 1:59 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Ahmad Humayun wrote: > > I need to create an atomic section in Python code i.e. there is no > > context switch to any other thread during the running of that piece of > > code. Would would do the trick? > > use a lock, and make sure that anyone that needs access to the shared > state you're manipulating in that section uses the same lock. > > lock = threading.Lock() # or RLock() etc [1] > > with lock: > section > > this only works if everyone honors the lock, of course; there's no way > in Python to lock out non-cooperating external threads. > > </F> > > 1) seehttp://effbot.org/zone/thread-synchronization.htm
Thats true, but this will ensure mutual exclusion; not atomicity thanks again, -- http://mail.python.org/mailman/listinfo/python-list