diff --git a/electrum/gui/qml/qechannellistmodel.py b/electrum/gui/qml/qechannellistmodel.py index 296b885ee..50fd55dd2 100644 --- a/electrum/gui/qml/qechannellistmodel.py +++ b/electrum/gui/qml/qechannellistmodel.py @@ -4,7 +4,7 @@ from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject from PyQt5.QtCore import Qt, QAbstractListModel, QModelIndex from electrum.logging import get_logger -from electrum.util import Satoshis, register_callback +from electrum.util import Satoshis, register_callback, unregister_callback from electrum.lnutil import LOCAL, REMOTE from .qetypes import QEAmount @@ -36,6 +36,7 @@ class QEChannelListModel(QAbstractListModel): # methods of this class only, and specifically not be # partials, lambdas or methods of subobjects. Hence... register_callback(self.on_network, interests) + self.destroyed.connect(lambda: self.on_destroy()) def on_network(self, event, *args): if event == 'channel': @@ -56,6 +57,8 @@ class QEChannelListModel(QAbstractListModel): else: self._logger.debug('unhandled event %s: %s' % (event, repr(args))) + def on_destroy(self): + unregister_callback(self.on_network) def rowCount(self, index): return len(self.channels) diff --git a/electrum/gui/qml/qewallet.py b/electrum/gui/qml/qewallet.py index b72dd2012..69d621cf2 100644 --- a/electrum/gui/qml/qewallet.py +++ b/electrum/gui/qml/qewallet.py @@ -7,15 +7,16 @@ import threading from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QUrl, QTimer from electrum.i18n import _ -from electrum.util import register_callback, Satoshis, format_time, parse_max_spend, InvalidPassword +from electrum.util import (register_callback, unregister_callback, + Satoshis, format_time, parse_max_spend, InvalidPassword) from electrum.logging import get_logger from electrum.wallet import Wallet, Abstract_Wallet from electrum.storage import StorageEncryptionVersion from electrum import bitcoin from electrum.transaction import PartialTxOutput -from electrum.invoices import (Invoice, InvoiceError, - PR_DEFAULT_EXPIRATION_WHEN_CREATING, PR_PAID, - PR_UNPAID, PR_UNKNOWN, PR_EXPIRED, PR_UNCONFIRMED) +from electrum.invoices import (Invoice, InvoiceError, + PR_DEFAULT_EXPIRATION_WHEN_CREATING, PR_PAID, + PR_UNPAID, PR_UNKNOWN, PR_EXPIRED, PR_UNCONFIRMED) from .qeinvoicelistmodel import QEInvoiceListModel, QERequestListModel from .qetransactionlistmodel import QETransactionListModel @@ -86,6 +87,7 @@ class QEWallet(AuthMixin, QObject): # methods of this class only, and specifically not be # partials, lambdas or methods of subobjects. Hence... register_callback(self.on_network, interests) + self.destroyed.connect(lambda: self.on_destroy()) @pyqtProperty(bool, notify=isUptodateChanged) def isUptodate(self): @@ -154,6 +156,8 @@ class QEWallet(AuthMixin, QObject): else: self._logger.debug('unhandled event: %s %s' % (event, str(args))) + def on_destroy(self): + unregister_callback(self.on_network) def add_tx_notification(self, tx): self._logger.debug('new transaction event')