def close(self): with self.lock: if self.is_closed: return self.is_closed = True log.debug("Closing connection (%s) to %s", id(self), self.endpoint) self._writable = False self._readable = False # We don't have to wait for this to be closed, we can just schedule it self.create_timer(0, partial(asyncore.dispatcher.close, self)) log.debug("Closed socket to %s", self.endpoint) if not self.is_defunct: self.error_all_requests( ConnectionShutdown("Connection to %s was closed" % self.endpoint)) #This happens when the connection is shutdown while waiting for the ReadyMessage if not self.connected_event.is_set(): self.last_error = ConnectionShutdown( "Connection to %s was closed" % self.endpoint) # don't leave in-progress operations hanging self.connected_event.set()
def send_msg(self, msg, cb): if self.is_defunct: raise ConnectionShutdown("Connection to %s is defunct" % self.host) elif self.is_closed: raise ConnectionShutdown("Connection to %s is closed" % self.host) try: request_id = self._id_queue.get_nowait() except Queue.EMPTY: raise ConnectionBusy( "Connection to %s is at the max number of requests" % self.host) self._callbacks[request_id] = cb self.push(msg.to_string(request_id, compression=self.compressor)) return request_id
def send_msg(self, msg, cb, wait_for_id=False): if self.is_defunct: raise ConnectionShutdown("Connection to %s is defunct" % self.host) elif self.is_closed: raise ConnectionShutdown("Connection to %s is closed" % self.host) if not wait_for_id: try: request_id = self._id_queue.get_nowait() except Queue.Empty: raise ConnectionBusy( "Connection to %s is at the max number of requests" % self.host) else: request_id = self._id_queue.get() self._callbacks[request_id] = cb self.push(msg.to_string(request_id, self.protocol_version, compression=self.compressor)) return request_id
def _error_all_callbacks(self, exc): new_exc = ConnectionShutdown(str(exc)) for cb in self._callbacks.values(): try: cb(new_exc) except Exception: log.warn("Ignoring unhandled exception while erroring callbacks for a " "failed connection (%s) to host %s:", id(self), self.host, exc_info=True)
def close(self): with self.lock: if self.is_closed: return self.is_closed = True log.debug("Closing connection (%s) to %s", id(self), self.host) self._writable = False self._readable = False asyncore.dispatcher.close(self) log.debug("Closed socket to %s", self.host) if not self.is_defunct: self.error_all_requests( ConnectionShutdown("Connection to %s was closed" % self.host)) #This happens when the connection is shutdown while waiting for the ReadyMessage if not self.connected_event.is_set(): self.last_error = ConnectionShutdown("Connection to %s was closed" % self.host) # don't leave in-progress operations hanging self.connected_event.set()
def close(self): with self.lock: if self.is_closed: return self.is_closed = True log.debug("Closing connection (%s) to %s", id(self), self.host) self._libevloop.connection_destroyed(self) self._socket.close() log.debug("Closed socket to %s", self.host) # don't leave in-progress operations hanging if not self.is_defunct: self.error_all_callbacks( ConnectionShutdown("Connection to %s was closed" % self.host))
def close(self): with self.lock: if self.is_closed: return self.is_closed = True log.debug("Closing connection (%s) to %s", id(self), self.host) self.__class__._connection_destroyed(self) _loop_notifier.send() self._socket.close() # don't leave in-progress operations hanging if not self.is_defunct: self._error_all_callbacks( ConnectionShutdown("Connection to %s was closed" % self.host))
def _close(self): log.debug("Closing connection (%s) to %s" % (id(self), self.host)) if self._write_watcher: self._write_watcher.cancel() if self._read_watcher: self._read_watcher.cancel() if self._socket: self._loop.remove_writer(self._socket.fileno()) self._loop.remove_reader(self._socket.fileno()) self._socket.close() log.debug("Closed socket to %s" % (self.host, )) if not self.is_defunct: self.error_all_requests( ConnectionShutdown("Connection to %s was closed" % self.host)) # don't leave in-progress operations hanging self.connected_event.set()
def close(self): """ Disconnect and error-out all requests. """ with self.lock: if self.is_closed: return self.is_closed = True log.debug("Closing connection (%s) to %s", id(self), self.endpoint) reactor.callFromThread(self.transport.connector.disconnect) log.debug("Closed socket to %s", self.endpoint) if not self.is_defunct: self.error_all_requests( ConnectionShutdown("Connection to %s was closed" % self.endpoint)) # don't leave in-progress operations hanging self.connected_event.set()
def close(self): """ Disconnect and error-out all callbacks. """ with self.lock: if self.is_closed: return self.is_closed = True log.debug("Closing connection (%s) to %s", id(self), self.host) self.connector.disconnect() log.debug("Closed socket to %s", self.host) if not self.is_defunct: self.error_all_callbacks( ConnectionShutdown("Connection to %s was closed" % self.host)) # don't leave in-progress operations hanging self.connected_event.set()
def close(self): if self.is_closed: return self.is_closed = True log.debug("Closing connection to %s" % (self.host,)) if self._read_watcher: self._read_watcher.kill() if self._write_watcher: self._write_watcher.kill() if self._socket: self._socket.close() log.debug("Closed socket to %s" % (self.host,)) # don't leave in-progress operations hanging self.connected_event.set() if not self.is_defunct: self._error_all_callbacks( ConnectionShutdown("Connection to %s was closed" % self.host))
def close(self): with self.lock: if self.is_closed: return self.is_closed = True log.debug("Closing connection to %s" % (self.host, )) if self._read_watcher: self._read_watcher.stop() if self._write_watcher: self._write_watcher.stop() self._socket.close() with _loop_lock: _loop_notifier.send() # don't leave in-progress operations hanging if not self.is_defunct: self._error_all_callbacks( ConnectionShutdown("Connection to %s was closed" % self.host))
def close(self): with self.lock: if self.is_closed: return self.is_closed = True log.debug("Closing connection (%s) to %s", id(self), self.host) self._writable = False self._readable = False asyncore.dispatcher.close(self) log.debug("Closed socket to %s", self.host) self._loop.connection_destroyed(self) if not self.is_defunct: self.error_all_callbacks( ConnectionShutdown("Connection to %s was closed" % self.host)) # don't leave in-progress operations hanging self.connected_event.set()
def close(self): with self.lock: if self.is_closed: return self.is_closed = True log.debug("Closing connection to %s" % (self.host,)) self._writable = False self._readable = False asyncore.dispatcher.close(self) log.debug("Closed socket to %s" % (self.host,)) with _starting_conns_lock: _starting_conns.discard(self) # don't leave in-progress operations hanging self.connected_event.set() if not self.is_defunct: self._error_all_callbacks( ConnectionShutdown("Connection to %s was closed" % self.host))
def close(self): with self.lock: if self.is_closed: return self.is_closed = True log.debug("Closing connection (%s) to %s" % (id(self), self.host)) if self._read_watcher: self._read_watcher.kill(block=False) if self._write_watcher: self._write_watcher.kill(block=False) if self._socket: self._socket.close() log.debug("Closed socket to %s" % (self.host,)) if not self.is_defunct: self.error_all_requests( ConnectionShutdown("Connection to %s was closed" % self.host)) # don't leave in-progress operations hanging self.connected_event.set()
def close(self): with self.lock: if self.is_closed: return self.is_closed = True log.debug("Closing connection (%s) to %s" % (id(self), self.host)) cur_gthread = eventlet.getcurrent() if self._read_watcher and self._read_watcher != cur_gthread: self._read_watcher.kill() if self._write_watcher and self._write_watcher != cur_gthread: self._write_watcher.kill() if self._socket: self._socket.close() log.debug("Closed socket to %s" % (self.host, )) if not self.is_defunct: self.error_all_callbacks( ConnectionShutdown("Connection to %s was closed" % self.host)) # don't leave in-progress operations hanging self.connected_event.set()
def _error_all_callbacks(self, exc): new_exc = ConnectionShutdown(str(exc)) for cb in self._callbacks.values(): cb(new_exc)