PDA

View Full Version : Automatically load maya when it crashes


zoharl
12-20-2010, 09:37 AM
Hi,

I'm developing a plug-in and every time I have a bug, maya crashes. I would like a program that monitors maya, and reloads it when it crashes. If there's no such a thing, maybe I can write a python script, which would look for a maya.exe process every second or so, and reload maya when it can't find any.

Robert Bateman
12-20-2010, 12:24 PM
Then attach a debugger and fix the bug.

zoharl
12-20-2010, 12:27 PM
That's what I do, but I still need to load maya again. I said I need it, while I'm developing, each time I have a different bug.

zoharl
12-21-2010, 02:30 PM
Here it is:

ensure_maya_is_running.py


import win32api, win32process, win32con
import os, time

appPath = "C:\\Program Files\\Autodesk\\Maya2010\\bin\\maya.exe"

def isRunning(filename):
processes = win32process.EnumProcesses()
for pid in processes:
try:
handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS,False, pid)
exe = win32process.GetModuleFileNameEx(handle, 0)
if exe.lower() == filename.lower():
return True
except:
pass
return False

def main():
while 1:
if not isRunning(appPath):
print time.asctime(time.localtime())
print "Executing: ", appPath
os.startfile(appPath)
win32api.Sleep(1000)

main()


Robert, I'll send you my log to show you how many mouse clicks I saved ;)

sdserbos
12-23-2010, 04:41 PM
I tried running this on winXP64 running maya2010 and it only seems to pick up the 32 bit processes. Is there a way to have it recognize 64 processes?

It catches all the process IDs but I think that this
exe = win32process.GetModuleFileNameEx(handle, 0)
catches only the names of the 32 bit processes.

Thanks

berniebernie
12-23-2010, 04:58 PM
had to do this for some unrelated software, this works with maya in a win batchfile (.bat), can't remember who I nicked the errorlevel trick from.


@echo off
:loopme
PING 1.1.1.1 -n 1 -w 2000 >NUL
tasklist /fi "imagename eq maya.exe" 2> NUL | find /I /N "maya.exe">NUL
if "%ERRORLEVEL%"=="1" echo Restarting maya & maya.exe
goto loopme

sdserbos
12-23-2010, 05:04 PM
"like"

Thanks

zoharl
12-24-2010, 08:33 AM
Hey, this was my python exercise, I could have done it in two perl lines, but nice trick...
If the pywin32 doesn't declare the winapi function for 64bits, it should be loaded 'manually' from ctypes.

CGTalk Moderation
12-24-2010, 08:33 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.