Search code examples
pythongobject

Is there an alternative to gobject.timeout_add() in Python?


I'm using gobject.timeout_add() to display a timer in my project (dojotools).

I was wondering if there is any other way to achieve the same results, but without the gobject dependency.

The requirement is just calling a method repeatedly, in a certain time interval.


Solution

  • You can use a thread with time.sleep(interval) to achieve the same effect.

    import thread, time
    
    def timer():
        while True:
            time.sleep(1)
            # do something here
    
    thread.start_new_thread(timer, ())