How to stop a script?



There are times that my scripts get into infinite loop and I don’t know any way to stop them but to force Maya to close. Is there any other way?



Nope, you’ve gotta just kill the process.

One tip while you’re testing loops that have the potential to go infinite on you, is to put a catch in there that it’s only allowed to run, say 100,000 times before breaking the loop. That way you can test some crazy while loops without having to restart Maya when you forget to increment a counter.


For stuff like “while” loops I do stuff similar to what brentelliott already mentioned. Additionally the progressWindow command allows you to stop a loop/script by checking if the “esc” key has been pressed. Sometimes this is also helpful.


This is what I do:

put a line inside the loop like:

if (filetest -f c:\breakloop.txt) break; // or use “error” instead of “break”

then… if your program gets into a loop you want to break out of just create a file called “breakloop.txt” on the root of your C: drive. (don’t forget to delete this file before you run your script again!! :smiley: )

(and believe it or not this doesn’t significantly alter the execution speed by any noticable amount!)



Thank you so much!

Your answers helped me a lot.
I had no idea about these so many different methods!



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.