views:

142

answers:

1

Is there any way to block a critical area like with Java synchronized in Django?

+1  A: 

You can use locks to make sure that only one Thread will access a certain block of code at a time.

To do this, you simply create a Lock object then acquire the lock before the block of code you want to synchronize. An example:

lock = Lock()

lock.acquire()   # will block if another thread has lock
try:
    ... use lock
finally:
    lock.release() 

For more information , see http://effbot.org/zone/thread-synchronization.htm.

Justin Ardini