One more enhancement! I am also reviewing it
in
http://codereview.stackexchange.com/questions/131239/function-to-lock-a-file-using-memcache
def addToCart(filename):
ableToLock = memcache.add(filename, username)
if ableToLock:
if os.file.ispath(filename)
# I have a loc
Enhanced it a bit to to check if the file is really present as well before
I proceed ... Btw this has to be done after obtaining the lock otherwise
again race condition i.e not fileExists and ableToLock ableToLock and
fileExists is the order.
def addToCart(filename):
ableToLock = memca
>
> key = filename
> item = memcli:get(key)
> if (! defined item) {
> if (memcli:add(key . "_lock", lock_timeout_time, my_admin_username)) {
> [etc]
> } else {
> # lost the race, handle how you want
> }
> } else if (item.value == my_admin_username) {
> # good to go for t