44from Queue import Queue
55import functools
66from hazelcast .exception import create_exception , HazelcastInstanceNotActiveError , is_retryable_error , TimeoutError , \
7- AuthenticationError , TargetDisconnectedError
7+ AuthenticationError , TargetDisconnectedError , HazelcastClientNotActiveException
88from hazelcast .future import Future
99from hazelcast .lifecycle import LIFECYCLE_STATE_CONNECTED
1010from hazelcast .protocol .client_message import LISTENER_FLAG
@@ -154,7 +154,6 @@ def invoke_smart(self, invocation, ignore_heartbeat=False):
154154 else : # send to random address
155155 addr = self ._client .load_balancer .next_address ()
156156 self ._send_to_address (invocation , addr )
157-
158157 return invocation .future
159158
160159 def invoke_non_smart (self , invocation , ignore_heartbeat = False ):
@@ -251,9 +250,11 @@ def _handle_event(self, invocation, message):
251250 self .logger .warn ("Error handling event %s" , message , exc_info = True )
252251
253252 def _handle_exception (self , invocation , error , traceback = None ):
253+ if not self ._client .lifecycle .is_live :
254+ invocation .set_exception (HazelcastClientNotActiveException (error .message ), traceback )
255+ return
254256 if self .logger .isEnabledFor (logging .DEBUG ):
255- self .logger .debug ("Got exception for request %s: %s: %s" , invocation .request ,
256- type (error ).__name__ , error )
257+ self .logger .debug ("Got exception for request %s: %s: %s" , invocation .request , type (error ).__name__ , error )
257258 if isinstance (error , (AuthenticationError , IOError , HazelcastInstanceNotActiveError )):
258259 if self ._try_retry (invocation ):
259260 return
@@ -272,7 +273,6 @@ def _try_retry(self, invocation):
272273 return False
273274
274275 invoke_func = functools .partial (self .invoke , invocation )
275- self .logger .debug ("Rescheduling request %s to be retried in %s seconds" , invocation .request ,
276- RETRY_WAIT_TIME_IN_SECONDS )
276+ self .logger .debug ("Rescheduling request %s to be retried in %s seconds" , invocation .request , RETRY_WAIT_TIME_IN_SECONDS )
277277 self ._client .reactor .add_timer (RETRY_WAIT_TIME_IN_SECONDS , invoke_func )
278278 return True
0 commit comments