@@ -34,13 +34,14 @@ class AikidoSession:
3434 """
3535
3636 class Holder (object ):
37- def __init__ (self , fct , auth , max_conflict_retries = 5 , verify = True ):
37+ def __init__ (self , fct , auth , max_conflict_retries = 5 , verify = True , timeout = 30 ):
3838 self .fct = fct
3939 self .auth = auth
4040 self .max_conflict_retries = max_conflict_retries
4141 if not isinstance (verify , bool ) and not isinstance (verify , CA_Certificate ) and not not isinstance (verify , str ) :
4242 raise ValueError ("'verify' argument can only be of type: bool, CA_Certificate or str " )
4343 self .verify = verify
44+ self .timeout = timeout
4445
4546 def __call__ (self , * args , ** kwargs ):
4647 if self .auth :
@@ -50,10 +51,12 @@ def __call__(self, *args, **kwargs):
5051 else :
5152 kwargs ["verify" ] = self .verify
5253
54+ kwargs ["timeout" ] = self .timeout
55+
5356 try :
5457 do_retry = True
5558 retry = 0
56- while do_retry and retry < self .max_conflict_retries :
59+ while do_retry and retry < self .max_conflict_retries :
5760 ret = self .fct (* args , ** kwargs )
5861 do_retry = ret .status_code == 1200
5962 try :
@@ -84,7 +87,8 @@ def __init__(
8487 max_retries = 5 ,
8588 single_session = True ,
8689 log_requests = False ,
87- pool_maxsize = 10
90+ pool_maxsize = 10 ,
91+ timeout = 30 ,
8892 ):
8993 if username :
9094 self .auth = (username , password )
@@ -95,6 +99,7 @@ def __init__(
9599 self .max_retries = max_retries
96100 self .log_requests = log_requests
97101 self .max_conflict_retries = max_conflict_retries
102+ self .timeout = timeout
98103
99104 self .session = None
100105 if single_session :
@@ -133,12 +138,13 @@ def __getattr__(self, request_function_name):
133138
134139 auth = object .__getattribute__ (self , "auth" )
135140 verify = object .__getattribute__ (self , "verify" )
141+ timeout = object .__getattribute__ (self , "timeout" )
136142 if self .log_requests :
137143 log = object .__getattribute__ (self , "log" )
138144 log ["nb_request" ] += 1
139145 log ["requests" ][request_function .__name__ ] += 1
140146
141- return AikidoSession .Holder (request_function , auth , max_conflict_retries = self .max_conflict_retries , verify = verify )
147+ return AikidoSession .Holder (request_function , auth , max_conflict_retries = self .max_conflict_retries , verify = verify , timeout = timeout )
142148
143149 def disconnect (self ):
144150 pass
@@ -180,6 +186,8 @@ class Connection(object):
180186 max number of requests for a conflict error (1200 arangodb error). Does not work with gevents (grequests),
181187 pool_maxsize: int
182188 max number of open connections. (Not intended for grequest)
189+ timeout: int
190+ number of seconds to wait on a hanging connection before giving up
183191 """
184192
185193 LOAD_BLANCING_METHODS = {'round-robin' , 'random' }
@@ -199,7 +207,8 @@ def __init__(
199207 use_lock_for_reseting_jwt = True ,
200208 max_retries = 5 ,
201209 max_conflict_retries = 5 ,
202- pool_maxsize = 10
210+ pool_maxsize = 10 ,
211+ timeout = 30
203212 ):
204213
205214 if loadBalancing not in Connection .LOAD_BLANCING_METHODS :
@@ -215,6 +224,7 @@ def __init__(
215224 self .max_retries = max_retries
216225 self .max_conflict_retries = max_conflict_retries
217226 self .action = ConnectionAction (self )
227+ self .timeout = timeout
218228
219229 self .databases = {}
220230 self .verbose = verbose
@@ -295,7 +305,8 @@ def create_aikido_session(
295305 max_conflict_retries = self .max_conflict_retries ,
296306 max_retries = self .max_retries ,
297307 log_requests = False ,
298- pool_maxsize = self .pool_maxsize
308+ pool_maxsize = self .pool_maxsize ,
309+ timeout = self .timeout
299310 )
300311
301312 def create_grequest_session (
0 commit comments