Skip to content

Lock stuck on acquiring #3255

Open
Open
@shoang22

Description

@shoang22

Thanks for wanting to report an issue you've found in redis-py. Please delete this text and fill in the template below.
It is of course not always possible to reduce your code to a small test case, but it's highly appreciated to have as much data as possible. Thank you!

Version: What redis-py and what redis version is the issue happening on?

redis-py: 5.0.2
redis: 7.2.4

Platform: What platform / version? (For example Python 3.5.1 on Windows 7 / Ubuntu 15.10 / Azure)

MacOS Sonoma 14.4.1

Description: Description of your issue, stack traces from errors and code that reproduces the issue

I'm trying to perform a sanity check on Redis Locks (async version):

import redis.asyncio as redis
import tqdm
import asyncio

r = redis.Redis(decode_responses=True)


async def update():
    lock = r.lock("lock")
    await lock.acquire(blocking=True)
    k = await r.get("key")
    if int(k) < 0:
        raise ValueError(f"Value {k} is negative")
    await r.setex("key", 3600, -1)
    await asyncio.sleep(0.5)
    await r.setex("key", 3600, 1)
    await lock.release()


async def main():
    total = 100
    chunksize = 10
    await r.setex("key", 3600, 1)
    aws = [update() for _ in range(total)]
    with tqdm.tqdm(total=total) as pbar:
        for idx in range(0, total, chunksize):
            end = min(idx + chunksize, total)
            chunk = aws[idx:end]
            await asyncio.gather(*chunk)
            pbar.update(end - idx)
    

if __name__ == "__main__":
    asyncio.run(main())

For some reason, my code doesn't make it past the .acquire step. Am I making any syntax errors?

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