Maya Python Threading Problems

I want to create a remote camera / camera linking over IP system using the built in python in Maya 8.5

I need to use threading for the camera 'server' to run within maya.

If I call this:

import thread
import maya.cmds
cam_p = maya.cmds.camera('persp', q=True, p=True)
print cam_p

I get

[8.4017873142238102, 18.186533479473226, 40.095635297704753]

Which is fine, but if I create a thread and call it:

import thread
import maya.cmds

def remCamera_run(name):

thread.start_new_thread(remCamera_run, ( 'persp', ))

I get this:

Argument to query flag must be a boolean: # TypeError# File "", line 4, in nexCamera_run
# Traceback (most recent call last):

# Unhandled exception in thread started by
Starting persp

If I use e=True to set the value, it works, its just q=True in a thread that barfs.

Any thoughts on this are welcome - including a completely different approach if nescacsarry - I am using threading so I can have a socket open, listening for camera requests, and it won't block maya.

I'm not 100% certain about this, but I think you should be using the mocap interface which maya provides. If you look in the devkit, search for a sample called mayaclock or clock or something like that. That one and the other files in the same folder are examples on how to use the interface which provides recording, filtering and some other mocap related abilities.

I'm not completely convinced if it is ok to issue a MEL command from a custom thread since this could, if the developers at Autodesk had not taken care of serialization of MEL commands, cause the system to become unstable at some point and then crash. You would'nt like to see that happening after 5 mins into a recording session.

Though I have seen a special form of the executeCommand function in Python which is called something like executeCommandThreaded or something like that which seems to deal with serializing incoming command execution requests.

I don't know if it is possible to use the mocap interface with python.

QUOTE(Daniel_Faus @ 06/01/07, 12:00 AM) [snapback]267239[/snapback]
I'm not completely convinced if it is ok to issue a MEL command from a custom thread since this could, if the developers at Autodesk had not taken care of serialization of MEL commands, cause the system to become unstable at some point and then crash. You would'nt like to see that happening after 5 mins into a recording session.

Its not,your supposed to wrap them inside a wait for maya to execute them, read the manual theres 2 entire manual pages devoted to this (and their example is exactly the thing yoru developing). Anyway wraop your callback within a maya.utils.executeInMainThreadWithResult
Aside form the fact that this is the first thing they tell you about python and thread sin the manual, read it its not there for you to ignore.

However just out of curiosity why dont you just open up a command port (maya then automatically listens for socket for you) to maya and wrap the command ports data to a function that turns them into mel (or python). I mean its usually no more then 3 -5 lines of code thatway (and it works on nay maya not just 8.5). Aside for the fact taht you should use the mocap stuff for sure. but...