def _dispatch_exception(self, seq, raw): if __debug__: logger.debug('Dispatch exception(%s): %s', self, seq) self._last_recv = time.time() is_sync = False with self._async_events_lock: is_sync = seq not in self._async_callbacks if is_sync: self._sync_raw_exceptions[seq] = raw if __debug__: logger.debug( 'Dispatch sync exception(%s): %s - pass', self, seq) self._sync_events[seq].set() else: if __debug__: logger.debug( 'Dispatch async reply(%s): %s - start', self, seq) Connection._dispatch_exception(self, seq, raw) if __debug__: logger.debug( 'Dispatch async reply(%s): %s - complete', self, seq)
def sync_request(self, handler, *args): seq = self._send_request(handler, args) if __debug__: synclogger.debug('Sync request wait: {}'.format(seq)) self._sync_events[seq].wait() if __debug__: synclogger.debug('Sync request wait: {} - complete'.format(seq)) del self._sync_events[seq] if __debug__: synclogger.debug('Sync request process: {}'.format(seq)) is_response = False is_exception = False with self._sync_events_lock: is_response = seq in self._sync_raw_replies is_exception = seq in self._sync_raw_exceptions if is_response: if __debug__: synclogger.debug('Dispatch sync reply: {} - start'.format(seq)) Connection._dispatch_reply(self, seq, self._sync_raw_replies.pop(seq)) if __debug__: synclogger.debug( 'Dispatch sync reply: {} - complete'.format(seq)) if is_exception: if __debug__: synclogger.debug( 'Dispatch sync exception: {} - start'.format(seq)) Connection._dispatch_exception(self, seq, self._sync_raw_exceptions.pop(seq)) if __debug__: synclogger.debug( 'Dispatch sync exception: {} - complete'.format(seq)) if __debug__: synclogger.debug('Sync request: {} - complete'.format(seq)) if self.closed: raise EOFError('Connection was closed, seq: {}'.format(seq)) isexc, obj = self._sync_replies.pop(seq) if isexc: raise obj else: return obj
def _dispatch_exception(self, seq, raw): self._last_recv = time.time() sync = seq not in self._async_callbacks Connection._dispatch_exception(self, seq, raw) if sync: self._sync_events[seq].set()
def sync_request(self, handler, *args): seq = self._send_request(handler, args) if __debug__: synclogger.debug('Sync request wait(%s): %s / %s:%s %s (%s)', self, seq, *traceback.extract_stack()[-4]) self._sync_events[seq].wait() if __debug__: synclogger.debug('Sync request wait(%s): %s - complete', self, seq) del self._sync_events[seq] if __debug__: synclogger.debug('Sync request process(%s): %s', self, seq) is_response = False is_exception = False with self._sync_events_lock: is_response = seq in self._sync_raw_replies is_exception = seq in self._sync_raw_exceptions if is_response: if __debug__: synclogger.debug('Dispatch sync reply(%s): %s - start', self, seq) Connection._dispatch_reply(self, seq, self._sync_raw_replies.pop(seq)) if __debug__: synclogger.debug('Dispatch sync reply(%s): %s - complete', self, seq) if is_exception: if __debug__: synclogger.debug('Dispatch sync exception(%s): %s - start', self, seq) synclogger.debug( 'Dispatch sync exception(%s): %s - handler = %s(%s) args = %s', self, seq, self._HANDLERS[handler], handler, repr(args)) Connection._dispatch_exception(self, seq, self._sync_raw_exceptions.pop(seq)) if __debug__: synclogger.debug('Dispatch sync exception(%s): %s - complete', self, seq) if __debug__: synclogger.debug('Sync request(%s): %s - complete', self, seq) if self.closed: raise EOFError('Connection was closed, seq({}): {}'.format( self, seq)) isexc, obj = self._sync_replies.pop(seq) if isexc: raise obj else: return obj