From 9d86c97a801edbcc060d28c6bba99a659816365c Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Wed, 24 Jun 2020 18:39:46 -0300 Subject: [PATCH] [fix][ui] thread waiting error stack --- bauh/app.py | 2 ++ bauh/view/qt/thread.py | 3 +++ bauh/view/qt/window.py | 21 +++++++++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/bauh/app.py b/bauh/app.py index 4e9431ff..e7a16c71 100755 --- a/bauh/app.py +++ b/bauh/app.py @@ -1,3 +1,4 @@ +import faulthandler import os import sys import traceback @@ -14,6 +15,7 @@ def main(tray: bool = False): if not os.getenv('PYTHONUNBUFFERED'): os.environ['PYTHONUNBUFFERED'] = '1' + faulthandler.enable() urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) args = app_args.read() diff --git a/bauh/view/qt/thread.py b/bauh/view/qt/thread.py index b2f20a92..5688edb0 100644 --- a/bauh/view/qt/thread.py +++ b/bauh/view/qt/thread.py @@ -772,6 +772,9 @@ class NotifyPackagesReady(QThread): self.work = True self.signal_finished.emit() + def stop_working(self): + self.work = False + class NotifyInstalledLoaded(QThread): signal_loaded = pyqtSignal() diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index 18289f4b..dc9976d6 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -1,3 +1,4 @@ +import datetime import logging import operator import time @@ -100,6 +101,7 @@ class ManageWindow(QWidget): signal_user_res = pyqtSignal(bool) signal_root_password = pyqtSignal(str, bool) signal_table_update = pyqtSignal() + signal_stop_notifying = pyqtSignal() def __init__(self, i18n: I18n, icon_cache: MemoryCache, manager: SoftwareManager, screen_size, config: dict, context: ApplicationContext, http_client: HttpClient, logger: logging.Logger, icon: QIcon): @@ -376,6 +378,7 @@ class ManageWindow(QWidget): self.thread_notify_pkgs_ready = NotifyPackagesReady() self.thread_notify_pkgs_ready.signal_changed.connect(self._update_package_data) self.thread_notify_pkgs_ready.signal_finished.connect(self._update_state_when_pkgs_ready) + self.signal_stop_notifying.connect(self.thread_notify_pkgs_ready.stop_working) self.thread_ignore_updates = IgnorePackageUpdates(manager=self.manager) self._bind_async_action(self.thread_ignore_updates, finished_call=self.finish_ignore_updates) @@ -486,8 +489,7 @@ class ManageWindow(QWidget): self.table_container.setCursor(QCursor(Qt.WaitCursor)) def begin_apply_filters(self): - self.thread_notify_pkgs_ready.work = False - self.thread_notify_pkgs_ready.wait(5) + self.stop_notifying_package_states() self._begin_action(action_label=self.i18n['manage_window.status.filtering'], action_id=ACTION_APPLY_FILTERS) self.comp_manager.disable_visible_from_groups(GROUP_UPPER_BAR, GROUP_LOWER_BTS) @@ -502,13 +504,22 @@ class ManageWindow(QWidget): self._finish_action(ACTION_APPLY_FILTERS) self.update_bt_upgrade() + def stop_notifying_package_states(self): + if self.thread_notify_pkgs_ready.isRunning(): + self.signal_stop_notifying.emit() + + expires_at = datetime.datetime.now() + datetime.timedelta(seconds=5) + + while datetime.datetime.now() < expires_at and self.thread_notify_pkgs_ready.isRunning(): + time.sleep(0.1) + def _update_table_and_upgrades(self, pkgs_info: dict): self._update_table(pkgs_info=pkgs_info, signal=True) if self.pkgs: self._update_state_when_pkgs_ready() - self.thread_notify_pkgs_ready.work = False - self.thread_notify_pkgs_ready.wait(5) + + self.stop_notifying_package_states() self.thread_notify_pkgs_ready.pkgs = self.pkgs self.thread_notify_pkgs_ready.work = True self.thread_notify_pkgs_ready.start() @@ -943,6 +954,8 @@ class ManageWindow(QWidget): self._update_table(pkgs_info=pkgs_info) if new_pkgs: + self.stop_notifying_package_states() + self.thread_notify_pkgs_ready.work = True self.thread_notify_pkgs_ready.pkgs = self.pkgs self.thread_notify_pkgs_ready.start()