-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error with systray.shutdown() #26
Comments
Error appears to be in traybar.py, 123:
I got around it by just catching the runtime exception and moving on with my life, but I'm curious if this is intended functionality, or if maybe that should be wrapped in a try/except RuntimeException block? |
Same here. |
Here is a way to get around it: |
Wow, thanks for the hint to use win32_adapter.DestroyWindow(self.stray._hwnd), this is the only way I was able to remove dead icons from the tray. |
Is there any plan to fix this officially or? |
From what I understand, this issue happens when calling The example in the original description will "work" if not calling If there is a use case I'm missing or a different way we can get this traceback, please post a complete and minimal reproducible example. |
I see. Makes sense. What I want to do is shut down several processes when someone presses "Quit" on the traybar - some websocket connections. But, I'm showing the systray by using the "with"-method. So technically, when I press quit, the "with" statement will be broken out of, and I can just put my "shutdown websocket connections" code at the bottom of my code, after the "with" statement? |
No and yes. "Quit" doesn't cause the main thread to do anything by itself, so it will not cause an exit from the "with" statement. It only shuts down the icon thread. If you use the "with" statement in your main thread, it means that if you exit from the block, the icon gets shut down. So if you don't "listen" for Quit from the main thread, the program may simply exit the block, kill the icon without user interaction and then get to the cleanup part. i.e. you still need to do some sort of signaling from Here's an example of such signaling: from infi.systray import SysTrayIcon
from threading import Event
quit_event = Event()
def say_hello(systray):
print("Hello, World!")
def qcallback(systray):
quit_event.set()
menu_options = (("Say Hello", None, say_hello),)
systray = SysTrayIcon("icon.ico", "Example tray icon", menu_options, on_quit=qcallback)
with systray:
# main program goes here - normally with some sort of loop
# For this example we just wait until time passes or the quit event is set
print('I will quit in 30 seconds, unless "Quit" is selected from the tray bar icon')
quit_event.wait(timeout=30) # returns True if quit_event is set and False if not and timeout reached
# "shutdown" is called by the exit from the with block
# It's safe to call "shutdown" whether quit was pressed (so icon is already destroyed) or not.
# cleanup goes here
print("ended properly!") |
You need to shutdown from main thread like:
|
Code:
Not sure what happens, but this also appears to thoroughly bone the parent process. Terminal will accept ctrl+x but then no further input.
The text was updated successfully, but these errors were encountered: