[ui] fix: initialization dialog hanging sometimes

This commit is contained in:
Vinicius Moreira
2021-01-18 16:33:22 -03:00
parent f3ac25fb0f
commit 27a57135f3
2 changed files with 14 additions and 12 deletions

View File

@@ -60,6 +60,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Flatpak - Flatpak
- crashing when trying to retrieve size of runtimes subcomponents [#164](https://github.com/vinifmor/bauh/issues/164) - crashing when trying to retrieve size of runtimes subcomponents [#164](https://github.com/vinifmor/bauh/issues/164)
- UI - UI
- initialization dialog hanging sometimes (due to thread locking)
- displaying a popup when information of a given package is not available - displaying a popup when information of a given package is not available

View File

@@ -2,10 +2,9 @@ import datetime
import operator import operator
import time import time
from functools import reduce from functools import reduce
from threading import Lock
from typing import Tuple, Optional from typing import Tuple, Optional
from PyQt5.QtCore import QSize, Qt, QThread, pyqtSignal, QCoreApplication from PyQt5.QtCore import QSize, Qt, QThread, pyqtSignal, QCoreApplication, QMutex
from PyQt5.QtGui import QIcon, QCursor, QCloseEvent from PyQt5.QtGui import QIcon, QCursor, QCloseEvent
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QSizePolicy, QTableWidget, QHeaderView, QPushButton, \ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QSizePolicy, QTableWidget, QHeaderView, QPushButton, \
QProgressBar, QPlainTextEdit, QToolButton, QHBoxLayout QProgressBar, QPlainTextEdit, QToolButton, QHBoxLayout
@@ -38,8 +37,8 @@ class Prepare(QThread, TaskManager):
self.password_response = None self.password_response = None
self._tasks_added = set() self._tasks_added = set()
self._tasks_finished = set() self._tasks_finished = set()
self._add_lock = Lock() self._add_lock = QMutex()
self._finish_lock = Lock() self._finish_lock = QMutex()
def ask_password(self) -> Tuple[bool, Optional[str]]: def ask_password(self) -> Tuple[bool, Optional[str]]:
self.waiting_password = True self.waiting_password = True
@@ -63,42 +62,44 @@ class Prepare(QThread, TaskManager):
QCoreApplication.exit(1) QCoreApplication.exit(1)
self.manager.prepare(self, root_pwd, None) self.manager.prepare(self, root_pwd, None)
self._add_lock.acquire()
self.signal_started.emit(len(self._tasks_added)) self.signal_started.emit(len(self._tasks_added))
self._add_lock.release()
def update_progress(self, task_id: str, progress: float, substatus: str): def update_progress(self, task_id: str, progress: float, substatus: str):
self._add_lock.lock()
if task_id in self._tasks_added: if task_id in self._tasks_added:
self.signal_update.emit(task_id, progress, substatus) self.signal_update.emit(task_id, progress, substatus)
self._add_lock.unlock()
def update_output(self, task_id: str, output: str): def update_output(self, task_id: str, output: str):
self._add_lock.lock()
if task_id in self._tasks_added: if task_id in self._tasks_added:
self.signal_output.emit(task_id, output) self.signal_output.emit(task_id, output)
self._add_lock.unlock()
def register_task(self, id_: str, label: str, icon_path: str): def register_task(self, id_: str, label: str, icon_path: str):
self._add_lock.acquire() self._add_lock.lock()
if id_ not in self._tasks_added: if id_ not in self._tasks_added:
self._tasks_added.add(id_) self._tasks_added.add(id_)
self.signal_register.emit(id_, label, icon_path) self.signal_register.emit(id_, label, icon_path)
self._add_lock.release() self._add_lock.unlock()
def finish_task(self, task_id: str): def finish_task(self, task_id: str):
self._add_lock.acquire() self._add_lock.lock()
task_registered = task_id in self._tasks_added task_registered = task_id in self._tasks_added
self._add_lock.release() self._add_lock.unlock()
if not task_registered: if not task_registered:
return return
self._finish_lock.acquire() self._finish_lock.lock()
if task_id not in self._tasks_finished: if task_id not in self._tasks_finished:
self._tasks_finished.add(task_id) self._tasks_finished.add(task_id)
self.signal_finished.emit(task_id) self.signal_finished.emit(task_id)
self._finish_lock.release() self._finish_lock.unlock()
class CheckFinished(QThread): class CheckFinished(QThread):