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 object seems to not provide locking #258

Open
bmbouter opened this issue Mar 13, 2018 · 0 comments
Open

Lock object seems to not provide locking #258

bmbouter opened this issue Mar 13, 2018 · 0 comments

Comments

@bmbouter
Copy link

With aioetcd==0.4.5.0 I can't seem to get working Locks. This is my first version of usage so I'm not sure I can't speak to if this ever worked.

If I have two processes both which try to aquire the same lock with this code:

import asyncio
import os
import time

import aio_etcd as etcd
from aio_etcd.lock import Lock

client = etcd.Client()

async def some_coroutine():
    async with Lock(client, 'mylock') as my_lock:
        print('lock_acquired in pid {pid}'.format(pid=os.getpid()))
        time.sleep(10)
    print('lock_released in pid {pid}'.format(pid=os.getpid()))


loop = asyncio.get_event_loop()
loop.run_until_complete(some_coroutine())

OK then I run the code in parallel using two terminals each running python3 foo.py immediately after each other. If locking is working I expect to see something like this:

PID 1 acquire the lock
# 10 seconds pass
PID 1 release the lock
PID 2 acquire the lock
# 10 seconds pass
PID 2 release the lock

Instead I see something like this:

PID 1 acquire the lock
PID 2 acquire the lock
# 10 seconds pass
PID 1 release the lock
PID 2 release the lock

Does this work for others users?
Am I doing this wrong?
Any insight into how to fix, I could send a PR with a little guidance.

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