Skip to content

Trace trap when updating MenuItem.title while menu is displayed #228

Description

@cybershoe

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions