File tree 2 files changed +8
-3
lines changed
2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change 1
1
import asyncio
2
2
import logging
3
- import functools
4
3
from typing import (
5
4
Callable ,
6
5
Optional ,
@@ -61,7 +60,8 @@ async def acquire(self) -> QuerySession:
61
60
done , _ = await asyncio .wait ((queue_get , task_stop ), return_when = asyncio .FIRST_COMPLETED )
62
61
if task_stop in done :
63
62
queue_get .cancel ()
64
- return await self ._create_new_session ()
63
+ raise RuntimeError ("An attempt to take session from closed session pool." )
64
+
65
65
task_stop .cancel ()
66
66
session = queue_get .result ()
67
67
@@ -163,7 +163,7 @@ def __del__(self):
163
163
if self ._should_stop .is_set () or self ._loop .is_closed ():
164
164
return
165
165
166
- self ._loop .call_soon (functools . partial ( self .stop ) )
166
+ self ._loop .call_soon (self .stop )
167
167
168
168
169
169
class SimpleQuerySessionCheckoutAsync :
Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ def _create_new_session(self, timeout: Optional[float]):
47
47
return session
48
48
49
49
def acquire (self , timeout : Optional [float ] = None ) -> QuerySession :
50
+ start = time .monotonic ()
51
+
50
52
lock_acquire_timeout = timeout if timeout is not None else - 1
51
53
acquired = self ._lock .acquire (timeout = lock_acquire_timeout )
52
54
try :
@@ -60,6 +62,9 @@ def acquire(self, timeout: Optional[float] = None) -> QuerySession:
60
62
except queue .Empty :
61
63
pass
62
64
65
+ finish = time .monotonic ()
66
+ timeout = timeout - (finish - start ) if timeout is not None else None
67
+
63
68
start = time .monotonic ()
64
69
if session is None and self ._current_size == self ._size :
65
70
try :
You can’t perform that action at this time.
0 commit comments