Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock stuck on acquiring #3255

Open
shoang22 opened this issue May 29, 2024 · 0 comments
Open

Lock stuck on acquiring #3255

shoang22 opened this issue May 29, 2024 · 0 comments

Comments

@shoang22
Copy link

shoang22 commented May 29, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant