Skip to content

Commit 134982a

Browse files
committed
simplify lock classes
1 parent 6f70b24 commit 134982a

File tree

2 files changed

+6
-25
lines changed

2 files changed

+6
-25
lines changed

ydb/aio/coordination/lock.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@ def __init__(
2222
client,
2323
name: str,
2424
node_path: Optional[str] = None,
25-
count: int = 1,
26-
timeout_millis: int = 30000,
2725
):
2826
self._client = client
2927
self._driver = client._driver
3028
self._name = name
3129
self._node_path = node_path
3230

3331
self._req_id: Optional[int] = None
34-
self._count: int = count
35-
self._timeout_millis: int = timeout_millis
32+
self._count: int = 1
33+
self._timeout_millis: int = 30000
3634
self._next_req_id: int = 1
3735

3836
self._request_queue: asyncio.Queue = asyncio.Queue()

ydb/coordination/lock_sync.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
from typing import Optional
32

43
from ydb import issues
@@ -12,28 +11,20 @@ def __init__(
1211
client,
1312
name: str,
1413
node_path: Optional[str] = None,
15-
count: int = 1,
16-
timeout_millis: int = 30000,
17-
*,
18-
eventloop: Optional[asyncio.AbstractEventLoop] = None,
1914
):
2015
self._closed = False
2116
self._name = name
22-
self._loop = eventloop or _get_shared_event_loop()
23-
self._timeout_sec = timeout_millis / 1000.0
17+
self._loop = _get_shared_event_loop()
2418
self._caller = CallFromSyncToAsync(self._loop)
2519
self._client = client
2620
self._node_path = node_path
27-
self._count = count
28-
self._timeout_millis = timeout_millis
21+
self._timeout_sec = 30
2922

3023
async def _make_lock():
3124
return CoordinationLock(
3225
client=self._client,
3326
name=self._name,
3427
node_path=self._node_path,
35-
count=self._count,
36-
timeout_millis=self._timeout_millis,
3728
)
3829

3930
self._async_lock: CoordinationLock = self._caller.safe_call_with_result(_make_lock(), self._timeout_sec)
@@ -88,14 +79,6 @@ def close(self, timeout: Optional[float] = None):
8879
return
8980
t = timeout or self._timeout_sec
9081

91-
try:
92-
self._caller.safe_call_with_result(self._async_lock.release(), t)
93-
except Exception:
94-
pass
95-
96-
try:
97-
self._caller.safe_call_with_result(self._async_lock.close(True), t)
98-
except Exception:
99-
pass
100-
82+
self._caller.safe_call_with_result(self._async_lock.release(), t)
83+
self._caller.safe_call_with_result(self._async_lock.close(True), t)
10184
self._closed = True

0 commit comments

Comments
 (0)