fix infinite loop
This commit is contained in:
parent
bef244ba77
commit
32dc1297ec
1 changed files with 4 additions and 1 deletions
|
@ -27,6 +27,7 @@ class BlobDownloader:
|
||||||
self.scores: typing.Dict['KademliaPeer', int] = {}
|
self.scores: typing.Dict['KademliaPeer', int] = {}
|
||||||
self.failures: typing.Dict['KademliaPeer', int] = {}
|
self.failures: typing.Dict['KademliaPeer', int] = {}
|
||||||
self.connections: typing.Dict['KademliaPeer', asyncio.Transport] = {}
|
self.connections: typing.Dict['KademliaPeer', asyncio.Transport] = {}
|
||||||
|
self.is_running = asyncio.Event(loop=self.loop)
|
||||||
|
|
||||||
def should_race_continue(self, blob: 'AbstractBlob'):
|
def should_race_continue(self, blob: 'AbstractBlob'):
|
||||||
if len(self.active_connections) >= self.config.max_connections_per_download:
|
if len(self.active_connections) >= self.config.max_connections_per_download:
|
||||||
|
@ -79,8 +80,9 @@ class BlobDownloader:
|
||||||
blob = self.blob_manager.get_blob(blob_hash, length)
|
blob = self.blob_manager.get_blob(blob_hash, length)
|
||||||
if blob.get_is_verified():
|
if blob.get_is_verified():
|
||||||
return blob
|
return blob
|
||||||
|
self.is_running.set()
|
||||||
try:
|
try:
|
||||||
while not blob.get_is_verified():
|
while not blob.get_is_verified() and self.is_running.is_set():
|
||||||
batch: typing.Set['KademliaPeer'] = set()
|
batch: typing.Set['KademliaPeer'] = set()
|
||||||
while not self.peer_queue.empty():
|
while not self.peer_queue.empty():
|
||||||
batch.update(self.peer_queue.get_nowait())
|
batch.update(self.peer_queue.get_nowait())
|
||||||
|
@ -107,6 +109,7 @@ class BlobDownloader:
|
||||||
def close(self):
|
def close(self):
|
||||||
self.scores.clear()
|
self.scores.clear()
|
||||||
self.ignored.clear()
|
self.ignored.clear()
|
||||||
|
self.is_running.clear()
|
||||||
for transport in self.connections.values():
|
for transport in self.connections.values():
|
||||||
transport.close()
|
transport.close()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue