Skip to content

Question: why is blocking missing as a lock() parameter? #1348

@jenstroeger

Description

@jenstroeger

Just a question: considering that Lock sports a blocking parameter:

redis-py/redis/lock.py

Lines 66 to 67 in a3cfded

def __init__(self, redis, name, timeout=None, sleep=0.1,
blocking=True, blocking_timeout=None, thread_local=True):

why is that same parameter missing from the lock() function:

redis-py/redis/client.py

Lines 708 to 709 in b940d07

def lock(self, name, timeout=None, sleep=0.1, blocking_timeout=None,
lock_class=None, thread_local=True):

which defaults to creating a Lock instance? It would be nice to write

r = redis.StrictRedis()
with r.lock("my-lock", blocking=False):
    pass  # Do stuff.

which would either enter the with block if the lock was acquired, or not. In my case, I wouldn’t even need the LockError() here… (Now if with had an else it would be even more useful, alas 😉)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions