From 737480f86a6dd74fcbbc5db46d74528261f0377d Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 20 Aug 2020 22:51:24 +0200 Subject: [PATCH 1/3] run p[lugin proces in thread and keep QtApp event processing until it's finished --- pype/tools/pyblish_pype/control.py | 36 ++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/pype/tools/pyblish_pype/control.py b/pype/tools/pyblish_pype/control.py index 0162848f2b..a184fe60dc 100644 --- a/pype/tools/pyblish_pype/control.py +++ b/pype/tools/pyblish_pype/control.py @@ -9,8 +9,9 @@ import os import sys import traceback import inspect +import threading -from Qt import QtCore +from Qt import QtCore, QtWidgets import pyblish.api import pyblish.util @@ -28,6 +29,28 @@ class IterationBreak(Exception): pass +class ProcessThread(threading.Thread): + def __init__(self, plugin, context, instance): + super(ProcessThread, self).__init__() + + self.result = None + self.exception = None + + self.plugin = plugin + self.context = context + self.instance = instance + + def run(self): + try: + result = pyblish.plugin.process( + self.plugin, self.context, self.instance + ) + self.result = result + except Exception as exc: + self.exception = exc + + + class Controller(QtCore.QObject): # Emitted when the GUI is about to start processing; # e.g. resetting, validating or publishing. @@ -231,7 +254,16 @@ class Controller(QtCore.QObject): self.processing["nextOrder"] = plugin.order try: - result = pyblish.plugin.process(plugin, self.context, instance) + thread = ProcessThread(plugin, self.context, instance) + thread.start() + while thread.isAlive(): + QtWidgets.QApplication.processEvents() + + if thread.exception: + raise thread.exception + + result = thread.result + thread.join() # Make note of the order at which the # potential error error occured. if result["error"] is not None: From dbbf702430ff39083976b1b9b91543de1361da75 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 20 Aug 2020 22:54:22 +0200 Subject: [PATCH 2/3] moved thread join earlier --- pype/tools/pyblish_pype/control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pype/tools/pyblish_pype/control.py b/pype/tools/pyblish_pype/control.py index a184fe60dc..0947dcd734 100644 --- a/pype/tools/pyblish_pype/control.py +++ b/pype/tools/pyblish_pype/control.py @@ -259,11 +259,11 @@ class Controller(QtCore.QObject): while thread.isAlive(): QtWidgets.QApplication.processEvents() + thread.join() if thread.exception: raise thread.exception result = thread.result - thread.join() # Make note of the order at which the # potential error error occured. if result["error"] is not None: From 53a1dc3f7505e1740fa783b3572d4502a6bab686 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Fri, 21 Aug 2020 16:24:19 +0200 Subject: [PATCH 3/3] added reraising traceback stack instead of only exception --- pype/tools/pyblish_pype/control.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pype/tools/pyblish_pype/control.py b/pype/tools/pyblish_pype/control.py index 0947dcd734..d73c7efad7 100644 --- a/pype/tools/pyblish_pype/control.py +++ b/pype/tools/pyblish_pype/control.py @@ -11,6 +11,7 @@ import traceback import inspect import threading +import six from Qt import QtCore, QtWidgets import pyblish.api @@ -46,9 +47,8 @@ class ProcessThread(threading.Thread): self.plugin, self.context, self.instance ) self.result = result - except Exception as exc: - self.exception = exc - + except Exception: + self.exception = sys.exc_info() class Controller(QtCore.QObject): @@ -261,7 +261,7 @@ class Controller(QtCore.QObject): thread.join() if thread.exception: - raise thread.exception + six.reraise(*thread.exception) result = thread.result # Make note of the order at which the