rumps icon indicating copy to clipboard operation
rumps copied to clipboard

Timer object callbacks aren't executed asynchronously

Open garrettngarcia opened this issue 11 years ago • 4 comments

In the example below, the function "a" is not being called asynchronously. The UI thread is blocked during each call to time.sleep and a spinner cursor is shown for 20 seconds.

I may just be misunderstanding how Timer objects are supposed to work. If that's the case, can you let me know if rumps includes a way to execute Timer callbacks (the "a" function in this case) in a separate thread?

import rumps
import time

def a(_):
    print "blah"
    time.sleep(20)

if __name__ == "__main__":
    app = rumps.App('TestApp', menu=('Fake', 'All timers', 'Start timer', 'Stop timer'))
    global_namespace_timer = rumps.Timer(a, 30)
    global_namespace_timer.start()
    app.run()

garrettngarcia avatar Oct 15 '14 06:10 garrettngarcia

I think this is a bug. From what I've read in the documentation for the Timer class:

Python abstraction of an Objective-C event timer in a new thread for application.

http://rumps.readthedocs.org/en/latest/Timer.html

dalleng avatar Jan 14 '15 19:01 dalleng

A possible workaround is to use python's Timer class in the threading module.

dalleng avatar Jan 14 '15 20:01 dalleng

Is it resolved? I am still facing this issue.

vikashbajaj avatar Sep 13 '15 19:09 vikashbajaj

@dalleng can you give an example on how I can use time with threading to make it run async? The timer stops working when I have the app menu open.

scottydelta avatar Apr 14 '16 05:04 scottydelta