def close(self): ''' Send the quit message and close the socket ''' if self.socket is None: raise Error("Already closed") send_data = struct.pack('<i', 1) + int2byte(COM_QUIT) self.wfile.write(send_data) self.wfile.close() self.rfile.close() self.socket.close() self.socket = None self.rfile = None self.wfile = None
def close(self): ''' Send the quit message and close the socket ''' if self.socket is None: raise Error("Already closed") send_data = struct.pack('<i', 1) + int2byte(COM_QUIT) try: self._write_bytes(send_data) except Exception: pass finally: sock = self.socket self.socket = None self._rfile = None sock.close()
def defaulterrorhandler(connection, cursor, errorclass, errorvalue): raise err = errorclass, errorvalue if cursor: cursor.messages.append(err) else: connection.messages.append(err) del cursor del connection if not issubclass(errorclass, Error): raise Error(errorclass, errorvalue) else: raise errorclass, errorvalue
def ping(self, reconnect=True): ''' Check if the server is alive ''' if self.socket is None: if reconnect: self._connect() reconnect = False else: raise Error("Already closed") try: self._execute_command(COM_PING, "") return self._read_ok_packet() except Exception: if reconnect: self._connect() return self.ping(False) else: raise