[Bug] Crash with PySimpleGUI + psgtray + PyGame
まだ誰も着手していません。
評価
調査の方向性
指定された Python、PySimpleGUI、pygame、tkinter のバージョンを使って、縮小した psgtray-test.py サンプルを Windows 上で実行し、その後クラッシュ条件を比較します。まず、psgtray/psgtray.py と pystray/_win32.py の traceback エントリ、および window.read(timeout) と pygame.event.get() の呼び出しを確認します。メニュー操作によって fatal な GIL クラッシュが発生しなくなり、トレイの動作が引き続き使用可能であれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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)
- 主要言語
- Python
- スター
- 13.8k
- フォーク
- 1.8k
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
PySimpleGUI/PySimpleGUI のほかの issue
-
Bug Done - Install Dev Build (see docs for how) Platform Specific Issue - Linux Port - TK
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
PySimpleGUI/PySimpleGUI#6904 · コメント 15 件 ·
-
Bug Demo Programs Done - Install Dev Build (see docs for how) Interoperability Port - TK workaround available
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
PySimpleGUI/PySimpleGUI#6900 · コメント 1 件 ·
-
Done - Install Dev Build (see docs for how) enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
PySimpleGUI/PySimpleGUI#3251 · コメント 12 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 74/100
PySimpleGUI/PySimpleGUI#6906 · コメント 1 件 · リアクション 1 件 ·
-
Bug Done - Install Dev Build (see docs for how) Port - TK
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
PySimpleGUI/PySimpleGUI#6902 · コメント 1 件 ·
PySimpleGUI/PySimpleGUI の issue をすべて見る
似ている issue
-
essnmx good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
-
[Feature] 奇物选择添加优先级 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
syfoud/Simulated_Scepter#174 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Giskard-AI/giskard-oss#2840 · コメント 1 件 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success オープンarea: repo bug perceived difficulty: 2
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
yeti-platform/yeti#1380 ·