<p>对此有两种不同的答案。</p>
<p>Maya脚本实际上应该在主UI线程中运行,如果从一个单独的线程运行,它们有很多方法会使您出错。Maya包含一个名为<code>maya.utils</code>的模块,该模块在主线程中包含延迟求值的方法。下面是一个简单的例子:</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>这将允许您从单独的线程处理maya ui(utils中还有另一个方法允许调用线程等待响应)。这是一张<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>然而,这并不能让你绕过问题的第二个方面。Maya python不会为您在处理器之间分割作业:<code>threading</code>将允许您创建单独的线程,但它们都共享同一python intepreter,<a href="https://stackoverflow.com/questions/1294382/what-is-a-global-interpreter-lock-gil/1294402#1294402">global interpreter lock</a>将意味着它们最终会等待它,而不是单独运行。</p>
<p>您不能使用<code>multiprocessing</code>模块,至少不能使用AFAIK,因为它会生成新的Maya,而不是将脚本执行推送到您正在运行的Maya中的其他处理器中。撇开Python不谈,Maya是一个旧程序,在任何情况下都不是很面向多核的。试试XSI:)</p>
<p>在任何情况下,在Maya中的任何线程处理都是很棘手的——如果您在没有上述延迟执行的情况下触摸主应用程序(基本上是API或Maya.whatever模块中的任何函数),您可能会使Maya崩溃。只有在必要时才使用。</p>
<p>另外,顺便说一下,不能在批处理模式下使用executeferred等,因为它们是使用主UI循环实现的。</p>