I am attempting to update the title of a MenuItem based on the output of a process in another thread. Intermittenty (5-50% of the time), if the menu is diplayed when the update occurs, the app crashes with a trace trap. Having the mouse pointer over the MenuItem seems to make a crash more likely, but it is not consistent.
Updating the title periodically within a @timer does not cause a crash, but then the title is not updated while the menu is displayed.
Code to reproduce:
import rumps
from threading import Thread
import asyncio
rumps.debug_mode(True)
class ReproApp(rumps.App):
def __init__(self):
super().__init__("Repro App")
self.dynamic_menu_item = rumps.MenuItem("Dynamic Option")
self.menu = [self.dynamic_menu_item]
self.loop = asyncio.new_event_loop()
Thread(
target=self._start_background_loop, args=(self.loop,), daemon=True
).start()
asyncio.run_coroutine_threadsafe(self.test_coro(), self.loop)
def update_menu_item(self, title):
self.dynamic_menu_item.title = title
async def test_coro(self):
count = 0
while True:
count += 1
self.update_menu_item(f"updated {count} times")
await asyncio.sleep(1)
def _start_background_loop(self, loop: asyncio.AbstractEventLoop) -> None:
asyncio.set_event_loop(loop)
loop.run_forever()
def main() -> None:
repro_app = ReproApp()
repro_app.run()
if __name__ == "__main__":
main()
output:
❯ python repro.py
[1] 59607 trace trap python repro.py
I am attempting to update the title of a MenuItem based on the output of a process in another thread. Intermittenty (5-50% of the time), if the menu is diplayed when the update occurs, the app crashes with a trace trap. Having the mouse pointer over the MenuItem seems to make a crash more likely, but it is not consistent.
Updating the title periodically within a
@timerdoes not cause a crash, but then the title is not updated while the menu is displayed.Code to reproduce:
output: