File: lock.py

package info (click to toggle)
python-aioredlock 0.7.3-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 184 kB
  • sloc: python: 608; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 569 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import attr


@attr.s
class Lock:

    lock_manager = attr.ib()
    resource = attr.ib()
    id = attr.ib()
    lock_timeout = attr.ib(default=10.0)
    valid = attr.ib(default=False)

    async def __aenter__(self):
        return self

    async def __aexit__(self, exc_type, exc, tb):
        await self.lock_manager.unlock(self)

    async def extend(self):
        await self.lock_manager.extend(self)

    async def release(self):
        await self.lock_manager.unlock(self)

    async def is_locked(self):
        return await self.lock_manager.is_locked(self)