I’ve been debugging an issue with a function that is triggered with a script job, and it’s been difficult because the errors are mysteriously suppressed – but only when triggered by the script job. It’s possible that there’s something fundamental about script jobs that I just do not yet understand.
Here’s what I’m seeing: when an exception occurs in the triggered function, the error and stack trace that should be logged is instead totally silenced… until the job is killed. When you do kill the job, the error will pop as if it had just occurred, even if many other operations have happened since.
Here’s some example code that illustrates the problem.
import pymel.core as pm
def foo():
print "selected:",pm.selected()
print "Everything is good!"
def bar():
print "selected:",pm.selected()
raise Exception("Something bad happened!!")
print "Everything is bad!" # This won't happen, of course
goodJob = pm.scriptJob( e=["SelectionChanged", foo])
badJob = pm.scriptJob( e=["SelectionChanged", bar])
Select some objects, see in the log we see the selected objects from both , but we do not see the exception pop. Kill the jobs…
pm.scriptJob( kill=goodJob )
pm.scriptJob( kill=badJob )
and now you’ll see the exception.
So what’s going on here? What can I do about it? Obviously this is bad, because if a user hits an error we’ll never know about it, since it appears everything is working fine (which is actually what happened here).