We're working in multithreaded python environment and need a mutual exclusion for a piece of code like:
lock = threading.Lock()
with lock:
# get data from shared storage
# process
# put back to shared storage
Currently it seems to me that binary semaphore threading.Semaphore()
and lock threading.Lock()
will similarly serve for this. Are there some pitfalls or gainings if I switch from lock to binary semaphore or vice versa?
NOTE: code running inside greenthreads (if that changes situation)