Browse Source

qt update checker: do not keep main window ref so it can gc-ed

related: #4905
master
SomberNight 5 years ago
parent
commit
0f6cbfba8e
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 5
      electrum/gui/qt/main_window.py
  2. 17
      electrum/gui/qt/update_checker.py

5
electrum/gui/qt/main_window.py

@ -299,7 +299,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.update_check_button.setText(_("Update to Electrum {} is available").format(v))
self.update_check_button.clicked.connect(lambda: self.show_update_check(v))
self.update_check_button.show()
self._update_check_thread = UpdateCheckThread(self)
self._update_check_thread = UpdateCheckThread()
self._update_check_thread.checked.connect(on_version_received)
self._update_check_thread.start()
@ -465,6 +465,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
def close_wallet(self):
if self.wallet:
self.logger.info(f'close_wallet {self.wallet.storage.path}')
self.wallet.thread = None
run_hook('close_wallet', self.wallet)
@profiler
@ -758,7 +759,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
_("Uses icons from the Icons8 icon pack (icons8.com).")))
def show_update_check(self, version=None):
self.gui_object._update_check = UpdateCheck(self, version)
self.gui_object._update_check = UpdateCheck(latest_version=version)
def show_report_bug(self):
msg = ' '.join([

17
electrum/gui/qt/update_checker.py

@ -16,6 +16,7 @@ from electrum import ecc
from electrum.i18n import _
from electrum.util import make_aiohttp_session
from electrum.logging import Logger
from electrum.network import Network
class UpdateCheck(QDialog, Logger):
@ -26,8 +27,7 @@ class UpdateCheck(QDialog, Logger):
"13xjmVAB1EATPP8RshTE8S8sNwwSUM9p1P",
)
def __init__(self, main_window, latest_version=None):
self.main_window = main_window
def __init__(self, *, latest_version=None):
QDialog.__init__(self)
self.setWindowTitle('Electrum - ' + _('Update Check'))
self.content = QVBoxLayout()
@ -54,7 +54,7 @@ class UpdateCheck(QDialog, Logger):
self.update_view(latest_version)
self.update_check_thread = UpdateCheckThread(self.main_window)
self.update_check_thread = UpdateCheckThread()
self.update_check_thread.checked.connect(self.on_version_retrieved)
self.update_check_thread.failed.connect(self.on_retrieval_failed)
self.update_check_thread.start()
@ -97,15 +97,15 @@ class UpdateCheckThread(QThread, Logger):
checked = pyqtSignal(object)
failed = pyqtSignal()
def __init__(self, main_window):
def __init__(self):
QThread.__init__(self)
Logger.__init__(self)
self.main_window = main_window
self.network = Network.get_instance()
async def get_update_info(self):
# note: Use long timeout here as it is not critical that we get a response fast,
# and it's bad not to get an update notification just because we did not wait enough.
async with make_aiohttp_session(proxy=self.main_window.network.proxy, timeout=120) as session:
async with make_aiohttp_session(proxy=self.network.proxy, timeout=120) as session:
async with session.get(UpdateCheck.url) as result:
signed_version_dict = await result.json(content_type=None)
# example signed_version_dict:
@ -131,12 +131,11 @@ class UpdateCheckThread(QThread, Logger):
return StrictVersion(version_num.strip())
def run(self):
network = self.main_window.network
if not network:
if not self.network:
self.failed.emit()
return
try:
update_info = asyncio.run_coroutine_threadsafe(self.get_update_info(), network.asyncio_loop).result()
update_info = asyncio.run_coroutine_threadsafe(self.get_update_info(), self.network.asyncio_loop).result()
except Exception as e:
self.logger.info(f"got exception: '{repr(e)}'")
self.failed.emit()

Loading…
Cancel
Save