def _terminate(self, conn):
"""terminate a sockets pair (two socket)
:type conn: socket.SocketType
:param conn: any one of the sockets pair
"""
try_close(conn) # close the first socket
# ------ close and clean the mapped socket, if exist ------
if conn in self.map:
_mapped_conn = self.map[conn]
try_close(_mapped_conn)
if _mapped_conn in self.map:
del self.map[_mapped_conn]
del self.map[conn] # clean the first socket
else:
_mapped_conn = None # just a fallback
# ------ callback --------
# because we are not sure which socket are assigned to callback,
# so we should try both
if conn in self.callbacks:
try:
self.callbacks[conn]()
except Exception as e:
log.error("traceback error: {}".format(e))
log.debug(traceback.format_exc())
del self.callbacks[conn]
elif _mapped_conn and _mapped_conn in self.callbacks:
try:
self.callbacks[_mapped_conn]()
except Exception as e:
log.error("traceback error: {}".format(e))
log.debug(traceback.format_exc())
del self.callbacks[_mapped_conn]
评论列表
文章目录