File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change 4
4
Optional ,
5
5
List ,
6
6
)
7
+ import time
7
8
import threading
8
9
import queue
9
10
@@ -56,6 +57,7 @@ def acquire(self, timeout: float) -> QuerySessionSync:
56
57
except queue .Empty :
57
58
pass
58
59
60
+ start = time .monotonic ()
59
61
if session is None and self ._current_size == self ._size :
60
62
try :
61
63
_ , session = self ._queue .get (block = True , timeout = timeout )
@@ -72,6 +74,11 @@ def acquire(self, timeout: float) -> QuerySessionSync:
72
74
73
75
logger .debug (f"Session pool is not large enough: { self ._current_size } < { self ._size } , will create new one." )
74
76
session = self ._create_new_session ()
77
+
78
+ finish = time .monotonic ()
79
+ if finish - start > timeout :
80
+ session .delete ()
81
+ raise issues .SessionPoolEmpty ("Timeout on acquire session" )
75
82
self ._current_size += 1
76
83
return session
77
84
You can’t perform that action at this time.
0 commit comments