From 805f72e0981dcced272806da6a90cf88d4fa19b7 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sun, 15 Jan 2017 22:21:19 +0100 Subject: [PATCH] Make objects to be send stoppable if not empty --- src/bitmessageqt/__init__.py | 2 ++ src/inventory.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 4cdcae30..04562fe6 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2721,6 +2721,8 @@ class MyForm(settingsmixin.SMainWindow): waitForSync = True elif reply == QtGui.QMessageBox.Cancel: return + else: + Missing().stop() if shared.statusIconColor == 'red': reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Not connected"), diff --git a/src/inventory.py b/src/inventory.py index 77291a5c..0e81e756 100644 --- a/src/inventory.py +++ b/src/inventory.py @@ -90,8 +90,11 @@ class Missing(object): super(self.__class__, self).__init__() self.lock = RLock() self.hashes = {} + self.stopped = False def add(self, objectHash): + if self.stopped: + return with self.lock: if not objectHash in self.hashes: self.hashes[objectHash] = {'peers':[], 'requested':0} @@ -105,6 +108,8 @@ class Missing(object): with self.lock: try: self.hashes[objectHash]['peers'].remove(current_thread().peer) + except KeyError: + return except ValueError: pass if len(self.hashes[objectHash]['peers']) == 0: @@ -131,6 +136,10 @@ class Missing(object): if objectHash in self.hashes: del self.hashes[objectHash] + def stop(self): + with self.lock: + self.hashes = {} + def threadEnd(self): with self.lock: for objectHash in self.hashes: