Increase the run time with sys.setExecutionLimit(msecs)

Hello guys… I’m working in some exercise with turtles (python).
Some draws take more time that I wanted, but there are not any infinite loop.
When I run the code, at some point it shows me this error.
I want to know where I can set the Execution Limit.

Please, I appreciate your help


TimeLimitError: Program exceeded run time limit. on line 100


Your program is running too long. Most programs in this book should run in less than 10 seconds easily. This probably indicates your program is in an infinite loop.

To Fix

Add some print statements to figure out if your program is in an infinte loop. If it is not you can increase the run time with sys.setExecutionLimit(msecs)

There is an example in the Exercises in Chapter 5 (Functions) of the Think Python book. You have to import sys module to use that command:

import sys
sys.setExecutionLimit(35000)    # this gives your code 35 secs to run

A simpler option, which may work, is to set your turtle’s speed to 0. It turns off animation and makes the turtle go as fast as possible:


1 Like

Thank you very very much Leonid!!! I appreciate it very much!