def calc_latency(self, node_to_calc):
""" calculate latency of given node, remove if node is not connected """
start = time.clock()
success = False
try:
for i in range(5):
node_to_calc.client.ping()
node_to_calc.latency = ((time.clock() - start) / 5) * 1000 # converting to ms
success = True
except: # node not connected
print(str(sys.exc_info()))
logger().warning("error attempting to ping an unregistered node: disconnecting node")
if node_to_calc in self.connections: # if a registered node disconnects
self.connections.remove(node_to_calc)
self.remove_from_peer_dict(node_to_calc)
try:
net_dao.update_failed_ping(node_to_calc)
except Exception as ex:
template = "An exception of type {0} occurred. Arguments:\n{1!r}"
message = template.format(type(ex).__name__, ex.args)
logger().warning(message)
return success
评论列表
文章目录