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) see http://effbot.org/zone/thread-synchronization.htm

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to