LC #42 Pipers Alley

View Full Version : Automatically load maya when it crashes

12-20-2010, 09:37 AM

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.

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.

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

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:
handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS,False, pid)
exe = win32process.GetModuleFileNameEx(handle, 0)
if exe.lower() == filename.lower():
return True
return False

def main():
while 1:
if not isRunning(appPath):
print time.asctime(time.localtime())
print "Executing: ", appPath


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

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.


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
PING -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

12-23-2010, 05:04 PM


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.