-
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
SysTrayIcon.shutdown produces threading join exception #32
Comments
Found out, that this only happens, when passing |
Fixed it with removing
in traybar.py and also building my own closing function with
|
Using |
Hey there again, sorry for the late answer, I already tried calling the shutdown() function in another thread and I can't block the main Thread because I have other things running on the Mainthread. But yeah, thanks for answering |
Hi @pythonmcpi , I know this is very late comment but I am facing a similar situation. Can you please provide a code example with respect to your comment. That would be really helpful |
@dibakarbose I can try looking for my original project, but I don't know if I'll be able to find it. I have too many abandoned projects :( EDIT The code below is from a project that I ended up abandoning on November 7, 2020, exactly 2 hours and 5 minutes after writing my original comment. It probably requires an Good luck. #import pystray
import contextlib
with contextlib.redirect_stdout(None):
import pygame
import sys
import subprocess
import os
from PIL import Image, ImageDraw
from infi.systray import SysTrayIcon as sti
import time
#from pystray import Icon as picon, Menu as pmenu, MenuItem as pitem
class Launcher(object):
def __init__(self, width=860, height=680):
## self.icon = picon('Launcher', self.generate_icon(), menu=pmenu(
## pitem(
## 'Quit',
## self.quit
## )
## )
## )
self.width = width
self.height = height
self.hidden = False
self.menu = (("Toggle Visibility", None, lambda e: self.toggle_visible()),)
self.icon = sti("icon.ico", "Launcher", self.menu, on_quit=lambda e: self.quit())
pygame.init()
def run(self):
self.running = True
#self.icon.run()
self.icon.start()
self.screen = pygame.display.set_mode((self.width, self.height), pygame.NOFRAME)
self.mainloop()
def generate_icon(self):
# Checkerboard Pattern
width = 32
height = 32
color1 = (255, 255, 255)
color2 = (0, 0, 0)
icon = Image.new('RGB', (width, height), color1)
dc = ImageDraw.Draw(icon)
dc.rectangle(
(width // 2, 0, width, height // 2),
fill=color2)
dc.rectangle(
(0, height // 2, width // 2, height),
fill=color2)
return icon
def toggle_visible(self):
if not self.running:
return
self.hidden = not self.hidden
if self.hidden:
pygame.display.iconify()
else:
pygame.display.deiconify()
def mainloop(self):
while self.running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.icon.shutdown()
def quit(self):
self.running = False
#self.icon.stop()
#self.icon.shutdown() # Shutdown has a line that joins the event monitor thread, but this function is called by the monitor thread, causing a RuntimeError. This line can be put in mainloop (which runs on main thread)
pygame.quit()
if __name__ == "__main__":
launcher = Launcher()
launcher.run()
#launcher.generate_icon().save("icon.ico", "ICO") # Save icon file |
Hey there,
Same issue as the one 2 years ago,
SystrayIcon.shutdown() produces a threading join error.
The text was updated successfully, but these errors were encountered: