diff --git a/pype/services/idle_manager/idle_manager.py b/pype/services/idle_manager/idle_manager.py index 57b827a37e..fd07eeec14 100644 --- a/pype/services/idle_manager/idle_manager.py +++ b/pype/services/idle_manager/idle_manager.py @@ -1,4 +1,5 @@ import time +import collections from Qt import QtCore, QtGui, QtWidgets from pype.vendor.pynput import mouse, keyboard from pypeapp import Logger @@ -9,7 +10,7 @@ class IdleManager(QtCore.QThread): Idle time resets on keyboard/mouse input. Is able to emit signals at specific time idle. """ - time_signals = {} + time_signals = collections.defaultdict(list) idle_time = 0 signal_reset_timer = QtCore.Signal() @@ -35,8 +36,6 @@ class IdleManager(QtCore.QThread): :param signal: signal that will be emitted (without objects) :type signal: QtCore.Signal """ - if emit_time not in self.time_signals: - self.time_signals[emit_time] = [] self.time_signals[emit_time].append(signal) @property @@ -70,12 +69,22 @@ class IdleManager(QtCore.QThread): if self.qaction and self.failed_icon: self.qaction.setIcon(self.failed_icon) - thread_mouse.signal_stop.emit() - thread_mouse.terminate() - thread_mouse.wait() - thread_keyboard.signal_stop.emit() - thread_keyboard.terminate() - thread_keyboard.wait() + + # Threads don't have their attrs when Qt application already finished + try: + thread_mouse.signal_stop.emit() + thread_mouse.terminate() + thread_mouse.wait() + except AttributeError: + pass + + try: + thread_keyboard.signal_stop.emit() + thread_keyboard.terminate() + thread_keyboard.wait() + except AttributeError: + pass + self._is_running = False self.log.info('IdleManager has stopped')