Closed avinash-550 closed 2 years ago
platform - windows 10 python 3.8x
Other information - change_ui function runs infinitely.
I'm working on Linux but I believe I have the same problem. The setup function is started in a new thread, and that function has to exit before icon.stop()
can work.
In my case, the function has a loop where it runs time.sleep(5)
. Solution is to replace this with threading.Event().wait()
...
def event_loop(icon):
"""Update the status every 5 seconds
"""
# This provides an interruptable timer
icon.timeout = threading.Event()
# We always need to do this...
icon.visible = True
while True:
if icon.timeout.wait(timeout=5):
# We were rudely interrupted - exit!
return
print("Updating status...")
Now to interrupt the thread and exit the main loop, put this in the "Quit" menu item callback:
icon.timeout.set()
icon.stop()
If this is a generally useful pattern, maybe it can be added to the docs?
Thank you for your report.
Stopping blocking until the setup function returns is expected behaviour, but I realise that it is not clearly stated.
On the master branch the documentation has been updated, and a workaround with a timeout and a warning log has been added.