【发布时间】:2015-04-01 03:38:37
【问题描述】:
我已经启动了一个自动保存脚本编辑器脚本(使用 Maya 2014),但它真的很不稳定,如果在保存的同时发生某些事情可能会崩溃。我也刚刚意识到即使不保存也会发生崩溃,所以我试图找出真正的问题是什么,最后几乎没有留下任何代码,但仍然能够复制它。
我对代码的想法是运行一个后台线程,它会在其中循环并每隔一段时间备份脚本,但每秒检查一个值以确保它没有被暂停或取消(取消将停止循环) .
我认为问题与 Maya 中后台线程的工作方式有关,因为如果加载/关闭脚本编辑器窗口或切换渲染视图设置上的选项卡(至少选择 Mental Ray,因为它似乎比默认渲染器需要更长的时间加载选项卡)。我想还有其他方法,但这些方法真的很容易找到。
在 while 循环中将其降低为 time.sleep() 后,我认为它为什么会导致崩溃真的没有意义。我还使用了 while time.time()>startTime+1 的另一个睡眠功能,以确保它不是时间模块,但它仍然会导致崩溃。
如果有人想尝试,这里是删减的代码,一旦你用AutoSave.start() 启动线程,如果你不断加载并关闭脚本编辑器窗口,你最终应该会得到一个运行时错误(即 R6025 pure virtual函数调用)。这可能需要多次尝试,但似乎总是最终会发生。
import threading, time
import pymel.core as pm
class AutoSaveThread(object):
def __init__( self ):
thread = threading.Thread(target=self.run, args=())
thread.daemon = True
thread.start()
def run(self):
while True:
time.sleep(1)
print "Open and close the script editor enough times and this will crash"
class AutoSave:
@classmethod
def start( self ):
AutoSaveThread()
我打开了十几个选项卡,因此加载/关闭比我没有打开的时间要长一些,这可能会增加可能发生崩溃的时间窗口。
作为记录,这是 Maya 中内置的一段代码,只要关闭脚本编辑器窗口,它就会始终运行。我认为这可能与我的修改版本保存有关,然后尝试同时保存,但它仍然崩溃,循环中没有发生任何事情。
global proc syncExecuterBackupFiles(){
global string $gCommandExecuter[];
global string $executerBackupFileName;
if(`optionVar -q saveActionsScriptEditor`) {
// clear the script editor temp dir first before writing temp files
string $scriptEditorTempDir = (`internalVar -userPrefDir` + "scriptEditorTemp/");
string $tempFiles[] = `getFileList -folder $scriptEditorTempDir`;
string $file;
for ($file in $tempFiles) {
sysFile -delete ($scriptEditorTempDir + $file);
}
// save all the executer control text to files
int $i = 0;
for($i = 0; $i < size($gCommandExecuter); $i++) {
cmdScrollFieldExecuter -e -storeContents $executerBackupFileName $gCommandExecuter[$i];
}
}
}
【问题讨论】:
标签: multithreading maya pymel