Skip to content

Lock object seems to not provide locking #258

Description

@bmbouter

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions