Skip to content

Cannot catch KeyboardInterrupt on blocking icon.run() call #177

@arija-ari

Description

@arija-ari

Hey :)

I want to use this in a tray-only script, so I attempt to block it. Some extra logic runs on a different thread that must be shutdown properly, so I have to catch ctrl+c, but it doesn't work:

    try:
        icon.run()
    except KeyboardInterrupt:
        print("Catched KeyboardInterrupt...")
    finally:
        print("Shutting down...")

The icon shows up, but hitting ctrl+c will crash icon.run and subsequently the entire process, icon.run does not raise KeyboardInterrupt or allows to continue operation, so all my sibling workers crash, too.

I tried to introduce signals, but icon.run is blocking on the main thread and thus takes precedence when sending the SIGINT. I also tried to spawn icon.run_detached in another thread, but this seems to only work if I have a mainloop in a GUI framework on the main thread, such as Tkinter, but I don't have that, so icon.run() should clearly be my mainloop.

I'm testing this on MacOS.

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