Locks

uWSGI supports a configurable number of locks you can use to synchronize workerprocesses. Lock 0 (zero) is always available, but you can add more with thelocks option. If your app has a lot of critical areas, holding andreleasing the same lock over and over again can kill performance.

  1. def use_lock_zero_for_important_things():
  2. uwsgi.lock() # Implicit parameter 0
  3. # Critical section
  4. uwsgi.unlock() # Implicit parameter 0
  5.  
  6. def use_another_lock():
  7. uwsgi.lock(1)
  8. time.sleep(1) # Take that, performance! Ha!
  9. uwsgi.unlock(1)