If your routine is causing a timeout, run it in a task thread instead of the render thread.
You will only experience a timeout if it is running in a render thread. Timeouts are not active for the main thread or task thread. So you may want to re-examine your code. If the device runs slower (some models) then it will take longer to execute your routine and cause a timeout. If you are accessing a server and the server takes longer than 30 seconds to respond, then you would get a url transfer timeout, not an execution timeout. But that is the only exception.