1
0

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

related: #4905
This commit is contained in:
SomberNight
2020-05-01 06:39:55 +02:00
parent 2105c6c4e6
commit 0f6cbfba8e
2 changed files with 11 additions and 11 deletions

View File

@@ -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()