pyblish / pyblish-qml

Pyblish QML frontend for Maya 2013+, Houdini 11+, Nuke 8+ and more
GNU Lesser General Public License v3.0
114 stars 44 forks source link

Old-style exceptions hang Pyblish QML #317

Open BigRoy opened 5 years ago

BigRoy commented 5 years ago

Issue

In Houdini we noticed that sometimes when a Houdini error was raised (that wasn't explicitly captured) in our plug-in that it would completely hang Pyblish QML. We found out that it was due to hou.Error not inheriting from the Python Exception and this code would not capture accordingly.

See this reproducible code snippet that also hangs outside of Houdini:

import pyblish.api

class RaiseOldStyleExceptionPlugin(pyblish.api.InstancePlugin):

    order = pyblish.api.ValidatorOrder
    label = "Raise Python 2 old-style exception"

    def process(self, instance):

        # define old style error
        class MyError:
            pass

        # this will hang Pyblish-QML indefinitely
        raise MyError

Solution

Adding a bare except would already solve it, but potentially we should still ignore KeyInterupt, etc. so we should set up a clever capture that at least ignores the ones we want to explicitly ignore.

So we'll need to do something like:

try:
    ...
except (KeyboardInterrupt, SystemExit, GeneratorExit):
    # Continue to raise these errors explicitly
    raise
except as error:
    # Capture any other error
mottosso commented 5 years ago

Is this still a problem?

Looking a little closer, it looks like the issue may stem from here, where Exception and all of its subclasses are caught.

except as error:

Didn't know that was possible, but that would probably take care of it; it's the same same effect anyway, the only reason Exception is there is due to Flake8/PyLint warnings.

BigRoy commented 5 years ago

Yes, I believe it is still an issue. :)