Executing a function after set interval

I want to force save my project file every x minutes, is there a maya function to add timed events?

The workaround that I’ve found is to create an extra thread and put a while loop into it and then use executeDeferred

class Test(threading.Thread):
    def __init__(self):
        threading.Thread__init__(self)

    def run(self):
        while True:
            maya.utils.executeDeferred(maya.cmds.file, s=True)
            time.sleep(300)

Thanks

Generally what you’re doing is the usual way – you probably want to use executeInMainThreadWithResult (is that the one you meant) or executeDeferred – otherwise pretty much anything in maya.cmds will crash in odd ways if triggered from another thread.

You can also use an idle-time scriptjob to check your timer, that won’t run if Maya is busy (probably a benefit for this application).

This github project emulates threads but uses idle events under the hood to implement timers and so on in a thread-safe way.

Thanks and yes there was a typo, I am using executeDeferred