[Bug] Crash with PySimpleGUI + psgtray + PyGame
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 28/100
Piste de recherche
Exécutez l’exemple réduit psgtray-test.py sous Windows avec les versions indiquées de Python, PySimpleGUI, pygame et tkinter, puis comparez les conditions du plantage. Commencez par les entrées du traceback dans psgtray/psgtray.py et pystray/_win32.py, ainsi que par les appels window.read(timeout) et pygame.event.get(). La tâche est terminée lorsque l’interaction avec le menu ne provoque plus le plantage fatal du GIL et que le comportement de la zone de notification reste utilisable.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Type of Issue (Enhancement, Error, Bug, Question)
Bug/Crash
Operating System
Windows 11
PySimpleGUI Port (tkinter, Qt, Wx, Web)
tkintr
Versions (NOTE - PSG4 is no longer supported)
Python Interpeter: C:\Users\vmix\GIL-crash\GIL-crash.venv\Scripts\python.exe
Python version: 3.12.3
Platform: Windows
Platform version: ('11', '10.0.22631', 'SP0', 'Multiprocessor Free')
Port: PySimpleGUI
tkinter version: 8.6.13
PySimpleGUI version: 5.0.6
PySimpleGUI filename: C:\Users\vmix\GIL-crash\GIL-crash.venv\Lib\site-packages\PySimpleGUI\PySimpleGUI.py
Your Experience In Months or Years (optional)
Years Python programming experience
5+
Years Programming experience overall
30+
Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)
no
Anything else you think would be helpful?
This may be related to https://github.com/PySimpleGUI/PySimpleGUI/issues/4880 because it only happens when window.read(timeout), not with window.read()
Troubleshooting
These items may solve your problem. Please check those you've done by changing - [ ] to - [X]
- None of your GUI code was generated by an AI algorithm like GPT
- Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.com
- Have upgraded to the latest release of PySimpleGUI on PyPI (lastest official version)
- duplicated the problem running python from the command line
- problem originally found using Python 3.10, reproduced with Python 3.12
Detailed Description
Problem: Program crashes with error
Fatal Python error: PyEval_RestoreThread: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
The full error dump is below
Duplicating the problem requires all of the following conditions:
- import pygame and call pygame.init()
- add a menu to the main PySimpleGUI window
- create a psgtray SystemTray
- call window.read(timeout) - the crash does not occur if no timeout
- call pygame.events.get() - the crash does not occur is this is not called
- select an item from the window menu - the crash occurs when the item is selected, the window.read() call does not return
Code To Duplicate
I was able to duplicate the problem by inserting code for the above into a reduced version of the psgtray sample program. I have not been able to reduce it to 10-20 lines
import PySimpleGUI as sg
from psgtray import SystemTray
import pygame
"""
Demonstrate GIL Crash with PyGame + psgtray
the following are necessary for the crash:
1. import pygame and call pygame.init()
2. add a menu to the main PySimpleGUI window
3. create a psgtray SystemTray
4. call window.read(timeout) - the crash does not occur if no timeout
5. call pygame.events.get() - the crash does not occur is this is not called
7. select an item from the window menu - the crash occurs when the item is selected, the window.read() call
does not return
"""
def main():
pygame.init( )
menu = ['',
['Show Window', 'Hide Window', 'Exit']]
tooltip = 'Tooltip'
winmenu = [['Menu',
['Show Window', 'Hide Window', 'Exit']]]
layout = [[sg.Menu(winmenu)],
[sg.Text('My PySimpleGUI Celebration Window - X will minimize to tray')],
[sg.T('Double clip icon to restore or right click and choose Show Window')],
[sg.Multiline(size=(60, 10), reroute_stdout=False, reroute_cprint=True, write_only=True, key='-OUT-')],
[sg.Button('Go'), sg.B('Hide Icon'), sg.B('Show Icon'), sg.B('Hide Window'), sg.Button('Exit')]]
window = sg.Window('Window Title', layout, finalize=True, enable_close_attempted_event=True)
tray = SystemTray(menu, single_click_events=False, window=window, tooltip=tooltip, icon=sg.DEFAULT_BASE64_ICON)
sg.cprint(sg.main_get_debug_data())
sg.cprint(sg.get_versions())
while True:
event, values = window.read(10)
if event == sg.TIMEOUT_EVENT:
events = pygame.event.get()
continue
# IMPORTANT step. It's not required, but convenient. Set event to value from tray
# if it's a tray event, change the event variable to be whatever the tray sent
if event == tray.key:
sg.cprint(f'System Tray Event = ', values[event], c='white on red')
event = values[event] # use the System Tray's event as if was from the window
if event in (sg.WIN_CLOSED, 'Exit'):
break
sg.cprint(event, values)
tray.show_message(title=event, message=values)
if event in ('Show Window', sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED):
window.un_hide()
window.bring_to_front()
elif event in ('Hide Window', sg.WIN_CLOSE_ATTEMPTED_EVENT):
window.hide()
tray.show_icon() # if hiding window, better make sure the icon is visible
# tray.notify('System Tray Item Chosen', f'You chose {event}')
tray.close() # optional but without a close, the icon may "linger" until moused over
window.close()
if __name__ == '__main__':
main()
Screenshot, Sketch, or Drawing
Watcha Makin?
I am working on an enhanced version of the project https://github.com/International-Anglican-Church/visca-joystick , adding better window support, configuration, controller hot plugging ...
Full Error dump
pygame 2.6.1 (SDL 2.28.4, Python 3.10.11)
Hello from the pygame community. https://www.pygame.org/contribute.html
Fatal Python error: PyEval_RestoreThread: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: initialized
Thread 0x00001164 (most recent call first):
File "C:\Users\vmix\psgtray-test\psgtray_test\.venv\lib\site-packages\pystray\_win32.py", line 147 in _mainloop
File "C:\Users\vmix\psgtray-test\psgtray_test\.venv\lib\site-packages\pystray\_win32.py", line 128 in _run
File "C:\Users\vmix\psgtray-test\psgtray_test\.venv\lib\site-packages\pystray\_base.py", line 212 in run
File "C:\Users\vmix\psgtray-test\psgtray_test\.venv\lib\site-packages\psgtray\psgtray.py", line 324 in _pystray_thread
File "C:\Users\vmix\AppData\Local\Programs\Python\Python310\lib\threading.py", line 953 in run
File "C:\Users\vmix\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016 in _bootstrap_inner
File "C:\Users\vmix\AppData\Local\Programs\Python\Python310\lib\threading.py", line 973 in _bootstrap
Current thread 0x00003d8c (most recent call first):
File "C:\Users\vmix\psgtray-test\psgtray_test\psgtray-test.py", line 70 in main
File "C:\Users\vmix\psgtray-test\psgtray_test\psgtray-test.py", line 110 in <module>
Extension modules: PIL._imaging, pygame.base, pygame.constants, pygame.rect, pygame.rwobject, pygame.surflock, pygame.bufferproxy, pygame.math, pygame.surface, pygame.display, pygame.draw, pygame.event, pygame.imageext, pygame.image, pygame.joystick, pygame.key, pygame.mouse, pygame.time, pygame.mask, pygame.pixelcopy, pygame.transform, pygame.font, pygame.mixer_music, pygame.mixer, pygame.scrap, pygame._freetype, PIL._imagingmath, PIL._webp (total: 28)
(.venv) VMIX:psgtray_test vmix$ .venv/Scripts/python psgtray-test.py
pygame 2.6.1 (SDL 2.28.4, Python 3.10.11)
Hello from the pygame community. https://www.pygame.org/contribute.html
Fatal Python error: PyEval_RestoreThread: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: initialized
Thread 0x00003bd0 (most recent call first):
File "C:\Users\vmix\psgtray-test\psgtray_test\.venv\lib\site-packages\pystray\_win32.py", line 147 in _mainloop
File "C:\Users\vmix\psgtray-test\psgtray_test\.venv\lib\site-packages\pystray\_win32.py", line 128 in _run
File "C:\Users\vmix\psgtray-test\psgtray_test\.venv\lib\site-packages\pystray\_base.py", line 212 in run
File "C:\Users\vmix\psgtray-test\psgtray_test\.venv\lib\site-packages\psgtray\psgtray.py", line 324 in _pystray_thread
File "C:\Users\vmix\AppData\Local\Programs\Python\Python310\lib\threading.py", line 953 in run
File "C:\Users\vmix\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016 in _bootstrap_inner
File "C:\Users\vmix\AppData\Local\Programs\Python\Python310\lib\threading.py", line 973 in _bootstrap
Current thread 0x00004404 (most recent call first):
File "C:\Users\vmix\psgtray-test\psgtray_test\psgtray-test.py", line 70 in main
File "C:\Users\vmix\psgtray-test\psgtray_test\psgtray-test.py", line 110 in <module>
Extension modules: PIL._imaging, pygame.base, pygame.constants, pygame.rect, pygame.rwobject, pygame.surflock, pygame.bufferproxy, pygame.math, pygame.surface, pygame.display, pygame.draw, pygame.event, pygame.imageext, pygame.image, pygame.joystick, pygame.key, pygame.mouse, pygame.time, pygame.mask, pygame.pixelcopy, pygame.transform, pygame.font, pygame.mixer_music, pygame.mixer, pygame.scrap, pygame._freetype, PIL._imagingmath, PIL._webp (total: 28)
(.venv) VMIX:psgtray_test vmix$ .venv/Scripts/python psgtray-test.py
pygame 2.6.1 (SDL 2.28.4, Python 3.10.11)
Hello from the pygame community. https://www.pygame.org/contribute.html
Fatal Python error: PyEval_RestoreThread: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: initialized
Thread 0x000041e0 (most recent call first):
File "C:\Users\vmix\psgtray-test\psgtray_test\.venv\lib\site-packages\pystray\_win32.py", line 147 in _mainloop
File "C:\Users\vmix\psgtray-test\psgtray_test\.venv\lib\site-packages\pystray\_win32.py", line 128 in _run
File "C:\Users\vmix\psgtray-test\psgtray_test\.venv\lib\site-packages\pystray\_base.py", line 212 in run
File "C:\Users\vmix\psgtray-test\psgtray_test\.venv\lib\site-packages\psgtray\psgtray.py", line 324 in _pystray_thread
File "C:\Users\vmix\AppData\Local\Programs\Python\Python310\lib\threading.py", line 953 in run
File "C:\Users\vmix\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016 in _bootstrap_inner
File "C:\Users\vmix\AppData\Local\Programs\Python\Python310\lib\threading.py", line 973 in _bootstrap
Current thread 0x000045b4 (most recent call first):
File "C:\Users\vmix\psgtray-test\psgtray_test\psgtray-test.py", line 70 in main
File "C:\Users\vmix\psgtray-test\psgtray_test\psgtray-test.py", line 110 in <module>
Extension modules: PIL._imaging, pygame.base, pygame.constants, pygame.rect, pygame.rwobject, pygame.surflock, pygame.bufferproxy, pygame.math, pygame.surface, pygame.display, pygame.draw, pygame.event, pygame.imageext, pygame.image, pygame.joystick, pygame.key, pygame.mouse, pygame.time, pygame.mask, pygame.pixelcopy, pygame.transform, pygame.font, pygame.mixer_music, pygame.mixer, pygame.scrap, pygame._freetype, PIL._imagingmath, PIL._webp (total: 28)
- Langage dominant
- Python
- Étoiles
- 13.8k
- Forks
- 1.8k
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de PySimpleGUI/PySimpleGUI
-
Bug Done - Install Dev Build (see docs for how) Platform Specific Issue - Linux Port - TK
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
PySimpleGUI/PySimpleGUI#6904 · 15 commentaires ·
-
Bug Demo Programs Done - Install Dev Build (see docs for how) Interoperability Port - TK workaround available
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
PySimpleGUI/PySimpleGUI#6900 · 1 commentaire ·
-
Done - Install Dev Build (see docs for how) enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
PySimpleGUI/PySimpleGUI#3251 · 12 commentaires ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 74/100
PySimpleGUI/PySimpleGUI#6906 · 1 commentaire · 1 réaction ·
-
Bug Done - Install Dev Build (see docs for how) Port - TK
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
PySimpleGUI/PySimpleGUI#6902 · 1 commentaire ·
Toutes les issues de PySimpleGUI/PySimpleGUI
Issues similaires
-
essnmx good first issue
Difficulté 1/5 Moins d'une heure Accessibilité débutants 95/100
-
[Feature] 奇物选择添加优先级 Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
syfoud/Simulated_Scepter#174 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Giskard-AI/giskard-oss#2840 · 1 commentaire ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Ouvertearea: repo bug perceived difficulty: 2
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
yeti-platform/yeti#1380 ·