Hey Asi, good to see you back in these threads. :) Maya, like Qt, isn't a big fan of having things run outside of their main threads. You can circumvent the issue by calling upon the overly descriptive command maya.utils.executeInMainThreadWithResult()which will queue the event in the main thread, rather than calling it directly.
More info here http://download.autodesk.com/global/docs/maya2014/en_us/files/Python_Python_and_threading.htm In code-land, you could wrap up your calls with something like this from maya import cmds from maya import utils class Wrapper(object): """Make thread-safe calls to maya.cmds Description Maya can't deal with commands coming in from threads other than main. This wrapper takes whatever we call and wrap it up using maya.utils.executeInMainThreadWithResult() How maya.utils.execu... has an argument signature that looks like this: (command, *args, **kwargs) Wrapper then intercepts any attribute-queries and wraps them up in a lambda that forwards the call to this method. """ def __init__(self, module): self._module = module def __getattr__(self, attr): wrapper = utils.executeInMainThreadWithResult command = getattr(self._module, attr) return lambda *args, **kwargs: wrapper( command, *args, **kwargs) cmds = Wrapper(cmds) That way, you could pretend like cmds is thread-safe, even though it would wrap things up for you in the background. Another alternative, since you're using QThreads rather than regular Python threads, is to set up a signal in the main thread. The QThread may call upon a signal in the main thread and Qt will do what Maya does with its descriptive method and wrap it up in a thread-safe manner for you. On 4 April 2014 04:51, Asi Sudai <[email protected]> wrote: > Hi gang, > > I'm getting a strange error in a very simple query of cmds.ls( type= > "transform", long=True ) running inside a PySide QThread. > > I extracted the issue into a basic example that reproduce the issue: > https://gist.github.com/asisudai/9967431 > > The error is ( it actually prints out upside down like this, might not be > related ): > > Flag 'long' must be passed a boolean argument: # TypeErrorreturn > maya.cmds.ls( type="transform", long=True ) # Will give TypeError on > long=True where True not a bool?! > # # File "c:/temp\threadTest.py", line 52, in funcA > result = self.function( *self.args, **self.kwargs ) > # # File "c:/temp\threadTest.py", line 80, in run > # Traceback (most recent call last): > > > > def funcA( data ): > print "%s inside funcA" %threading.current_thread().name > > ## Here's the issue: > # Running cmds.ls command will result in the TypeError where long=True > isn't a Bool. > return maya.cmds.ls( type="transform", long=True ) # Will give TypeError > on long=True where True not a bool?! > > ## While running this ( or any other module/code will work?! why? > # return [1,2,3] # Works > > > Any idea why? > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/210f2ebd-077f-42bf-af20-fbbdb7e57163%40googlegroups.com<https://groups.google.com/d/msgid/python_inside_maya/210f2ebd-077f-42bf-af20-fbbdb7e57163%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- *Marcus Ottosson* [email protected] -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOC7BkX%2BqB0N2%3DAPSpE7yPB5CW4tGyPV%2BwbSj83Wr3ZfHg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
