Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are really two different answers to this.</p> <p>Maya scripts are really supposed to run in the main UI thread, and there are lots of ways they can trip you up if run from a separate thread. Maya includes a module called <code>maya.utils</code> which includes methods for deferred evaluation in the main thread. Here's a simple example:</p> <pre><code>import maya.cmds as cmds import maya.utils as utils import threading def do_in_main(): utils.executeDeferred (cmds.sphere) for i in range(10): t = threading.Thread(target=do_in_main, args=()) t.start() </code></pre> <p>That will allow you to do things with the maya ui from a separate thread (there's another method in utils that will allow the calling thread to await a response too). Here's a <a href="http://download.autodesk.com/global/docs/maya2013/en_us/index.html?url=files/Python_Python_and_threading.htm,topicNumber=d30e727083" rel="nofollow noreferrer">link to the maya documentation on this module</a> </p> <p>However, this doesn't get you around the second aspect of the question. Maya python isn't going to split up the job among processors for you: <code>threading</code> will let you create separate threads but they all share the same python intepreter and the <a href="https://stackoverflow.com/questions/1294382/what-is-a-global-interpreter-lock-gil/1294402#1294402">global interpreter lock</a> will mean that they end up waiting for it rather than running along independently.</p> <p>You can't use the <code>multiprocessing</code> module, at least not AFAIK, since it spawns new mayas rather than pushing script execution out into other processors in the Maya you are running within. Python aside, Maya is an old program and not very multi-core oriented in any case. Try XSI :)</p> <p>Any threading stuff in Maya is tricky in any case - if you touch the main application (basically, any function from the API or a maya.whatever module) without the deferred execution above, you'll probably crash maya. Only use it if you have to.</p> <p>And, BTW, you cant use executeDeferred, etc in batch mode since they are implemented using the main UI loop.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload