Skip to content

Instantly share code, notes, and snippets.

import time
import threading
import redis, redis_lock
def locking(conn):
tid = str(threading.get_ident()).encode()
lock = redis_lock.Lock(conn, 'loclock', id=tid, expire=10)
if lock.acquire(blocking=False):
print("Got the lock.", str(tid))