Make objects to be send stoppable if not empty

This commit is contained in:
Peter Šurda 2017-01-15 22:21:19 +01:00
parent 94f0bdc731
commit 805f72e098
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
2 changed files with 11 additions and 0 deletions

View File

@ -2721,6 +2721,8 @@ class MyForm(settingsmixin.SMainWindow):
waitForSync = True waitForSync = True
elif reply == QtGui.QMessageBox.Cancel: elif reply == QtGui.QMessageBox.Cancel:
return return
else:
Missing().stop()
if shared.statusIconColor == 'red': if shared.statusIconColor == 'red':
reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Not connected"), reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Not connected"),

View File

@ -90,8 +90,11 @@ class Missing(object):
super(self.__class__, self).__init__() super(self.__class__, self).__init__()
self.lock = RLock() self.lock = RLock()
self.hashes = {} self.hashes = {}
self.stopped = False
def add(self, objectHash): def add(self, objectHash):
if self.stopped:
return
with self.lock: with self.lock:
if not objectHash in self.hashes: if not objectHash in self.hashes:
self.hashes[objectHash] = {'peers':[], 'requested':0} self.hashes[objectHash] = {'peers':[], 'requested':0}
@ -105,6 +108,8 @@ class Missing(object):
with self.lock: with self.lock:
try: try:
self.hashes[objectHash]['peers'].remove(current_thread().peer) self.hashes[objectHash]['peers'].remove(current_thread().peer)
except KeyError:
return
except ValueError: except ValueError:
pass pass
if len(self.hashes[objectHash]['peers']) == 0: if len(self.hashes[objectHash]['peers']) == 0:
@ -131,6 +136,10 @@ class Missing(object):
if objectHash in self.hashes: if objectHash in self.hashes:
del self.hashes[objectHash] del self.hashes[objectHash]
def stop(self):
with self.lock:
self.hashes = {}
def threadEnd(self): def threadEnd(self):
with self.lock: with self.lock:
for objectHash in self.hashes: for objectHash in self.hashes: