Distributed locking

James rent.lupin.road at gmail.com
Thu May 14 00:11:21 EDT 2009


Hey all, I'm looking for suggestions on how to tackle distributed
locking across several Python programs on several different machines.

- the objects to be locked are uniquely identified by an integer
- I need "one at a time" semantics for the lock: zero or one read-
writer at any point
- the operations to be performed on the objects are strictly limited
in duration (no more than 10 seconds)

As the operations have a maximum duration, my ideal solution would be
to lock the objects, and have them automatically unlock after some
time period even if the original lock-holder doesn't release them.

I'm currently playing with memcached as a locking mechanism as it's
simplicity and timeout fit my requirements well.

There is a check-and-set operation which atomically writes new data
iff the existing value hasn't been changed since we last looked.
However, their CAS operation doesn't handle the case of a non-existent
key..

Does anyone have suggestions on how I can do distributed locking to
take advantage of the time limit on operations?

Many thanks,
James



More information about the Python-list mailing list