[issue40075] _tkinter PythonCmd fails to acquire GIL
New submission from Thomas Holder : The attached demo application runs a Tkinter GUI and a PyQt GUI in the same thread. PyQt owns the main loop and keeps updating the Tkinter instance by calling `update()`. On Windows, when binding a "" event, resizing the Tk window will lead to a crash: ``` Fatal Python error: PyEval_RestoreThread: NULL tstate Current thread 0x1f1c (most recent call first): File "qt_tk_demo.py", line 50 in ``` This crash happens in `_tkinter.c` in `PythonCmd` inside the `ENTER_PYTHON` macro. The issue can be fixed by using `PyGILState_Ensure` and `PyGILState_Release` instead of the `ENTER_PYTHON` macro inside the `PythonCmd` function. -- components: Tkinter, Windows files: qt_tk_demo.py messages: 365064 nosy: Thomas Holder, paul.moore, steve.dower, tim.golden, zach.ware priority: normal severity: normal status: open title: _tkinter PythonCmd fails to acquire GIL type: crash Added file: https://bugs.python.org/file49002/qt_tk_demo.py ___ Python tracker <https://bugs.python.org/issue40075> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40075] _tkinter PythonCmd fails to acquire GIL
Change by Thomas Holder : -- keywords: +patch pull_requests: +18538 stage: -> patch review pull_request: https://github.com/python/cpython/pull/19178 ___ Python tracker <https://bugs.python.org/issue40075> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40075] _tkinter PythonCmd fails to acquire GIL
Thomas Holder added the comment: Attaching an even simpler example which doesn't use PyQt. It shows a native Windows dialog using ctypes. I could not reproduce the crash without showing any non-tk dialog. Steve's explanation sounds plausible. -- Added file: https://bugs.python.org/file49349/simple_tk_demo.py ___ Python tracker <https://bugs.python.org/issue40075> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40075] _tkinter PythonCmd fails to acquire GIL
Thomas Holder added the comment: I finally managed to test tstate_acquire.diff and it works perfectly! Should I close my pull request? Or update it with your patch? -- ___ Python tracker <https://bugs.python.org/issue40075> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40075] _tkinter PythonCmd fails to acquire GIL
Thomas Holder added the comment: All good, thanks for opening PR 22453! I'll close my old PR. -- ___ Python tracker <https://bugs.python.org/issue40075> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com