Unhandeled error in deferred
Hi I am using twistd to run a daemon which manage a device The issue occur in a LoopingCall # Create a looping call and assign waiting_update function to it self.waiting_loop = task.LoopingCall(self.waiting_update) def send(self): # If client isn't waiting for response and frame queue of the NetworkManager is not empty : if not self.waiting_response and self.network_manager.queue: # If first element of the queue is None : if self.network_manager.queue[0] == None: # Delete first element del self.network_manager.queue[0] # Recall the function self.send() # If first element of the queue is different than None : else: # Copy first element of the queue frame = self.network_manager.queue[0] # If debug is enabled print debugging string and frame if self.network_manager.debug: print(self.network_manager.lang['keypanel_sending_frame'], " ".join(frame[i:i+2] for i in range(0, len(frame), 2))) # Send frame to the KeyPanel self.transport.write(bytes.fromhex(frame)) # Set waiting response to True self.waiting_response = True def print_test(self): print ("Test errback ") # If loop isn't already running, start the loop if not self.waiting_loop.running: self.waiting_time = time.time() d = self.waiting_loop.start(1) d.addErrback(print_test) def waiting_update(self): # If waiting time is equal or greater than the limit : if time.time() >= self.waiting_time + self.network_manager.waiting_response_time: # Increment retry by 1 self.retry += 1 # If retry is equal or greater than the limit : if self.retry >= self.network_manager.send_retry_max: # If debug is enabled print debugging string if self.network_manager.debug: print(self.network_manager.lang['keypanel_fail_sending_frame'], self.network_manager.queue[0]) # Delete first element of the NetworkManager queue del self.network_manager.queue[0] # Reset retry variable self.retry = 0 # Reset waiting state self.waiting_reset() # If waiting time is lesser than the limit : else: # Waiting 1/2 second time.sleep(0.5) # Increment waiting time self.waiting_time = time.time() def waiting_reset(self): # Disable response waiting self.waiting_response = False # Stop the loop self.waiting_loop.stop() # Reset waiting time self.waiting_time = time.time() # Send the next frame in the queue self.send() When the internet connection is good everything works but if the cable is disconnected an error occurs in twisted.internet.defer which I can't catch Error message is [twisted.internet.defer#critical] Unhandled error in Deferred: [twisted.internet.defer#critical] Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/twisted/internet/base.py", line 913, in runUntilCurrent call.func(*call.args, **call.kw) File "/usr/local/lib/python3.7/dist-packages/twisted/internet/task.py", line 241, in __call__ d.addErrback(eb) File "/usr/local/lib/python3.7/dist-packages/twisted/internet/defer.py", line 333, in addErrback errbackKeywords=kw) File "/usr/local/lib/python3.7/dist-packages/twisted/internet/defer.py", line 311, in addCallbacks self._runCallbacks() --- <exception caught here> --- File "/usr/local/lib/python3.7/dist-packages/twisted/internet/defer.py", line 654, in _runCallbacks current.result = callback(current.result, *args, **kw) File "/usr/local/lib/python3.7/dist-packages/twisted/internet/task.py", line 236, in eb d.errback(failure) builtins.AttributeError: 'NoneType' object has no attribute 'errback' Do you have a proposal to resolve this issue Thank you
participants (1)
-
joel.tremblet@openflyers.com