fix possible division by zero

This commit is contained in:
Victor Shyba 2019-05-02 11:52:09 -03:00
parent 609cf42868
commit ac69fcbc5f

View file

@ -53,8 +53,8 @@ class BlobDownloader:
log.debug("keep peer %s:%i", peer.address, peer.tcp_port) log.debug("keep peer %s:%i", peer.address, peer.tcp_port)
self.failures[peer] = 0 self.failures[peer] = 0
self.connections[peer] = transport self.connections[peer] = transport
rough_speed = (bytes_received / (self.loop.time() - start)) if bytes_received else 0 elapsed = self.loop.time - start
self.scores[peer] = rough_speed self.scores[peer] = bytes_received / elapsed if bytes_received and elapsed else 0
async def new_peer_or_finished(self): async def new_peer_or_finished(self):
active_tasks = list(self.active_connections.values()) + [asyncio.sleep(1)] active_tasks = list(self.active_connections.values()) + [asyncio.sleep(1)]