Don't crash download thread if no connections

This commit is contained in:
Peter Šurda 2017-12-02 00:50:58 +01:00
parent 41ead2bfb5
commit a3398d6a17
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
1 changed files with 4 additions and 1 deletions

View File

@ -42,7 +42,10 @@ class DownloadThread(threading.Thread, StoppableThread):
# Choose downloading peers randomly
connections = BMConnectionPool().inboundConnections.values() + BMConnectionPool().outboundConnections.values()
random.shuffle(connections)
requestChunk = max(int(DownloadThread.maxRequestChunk / len(connections)), 1)
try:
requestChunk = max(int(DownloadThread.maxRequestChunk / len(connections)), 1)
except ZeroDivisionError:
requestChunk = 1
for i in connections:
now = time.time()
timedOut = now - DownloadThread.requestTimeout