Getting a Global Interpreter Lock (GIL) on Python 3.10

First of all, I wanted to use my project (RIDE) in Python 3.10 with a newer version of wxPython like 4.1.1. But the only available version on Linux is 4.0.7 (in Fedora 36 and Ubuntu 22.0.4).
I am happily using it in Fedora 36 (surprisingly), but today I tried to use it in Ubuntu, and got this weird error mentioning GIL. Searched the Web and finally found the meaning of the acronym. I actually found an interesting blog about a fix for a GIL, here.

Well, this is the output on Ubuntu 22.0.4:

~$ ride.py

Traceback (most recent call last):
  File "/home/tester/.local/lib/python3.10/site-packages/robotide/application/application.py", line 77, in OnInit
    self._plugin_loader.enable_plugins()
  File "/home/tester/.local/lib/python3.10/site-packages/robotide/application/pluginloader.py", line 36, in enable_plugins
    p.enable_on_startup()
  File "/home/tester/.local/lib/python3.10/site-packages/robotide/application/pluginconnector.py", line 52, in enable_on_startup
    self.enable()
  File "/home/tester/.local/lib/python3.10/site-packages/robotide/application/pluginconnector.py", line 57, in enable
    self._plugin.enable()
  File "/home/tester/.local/lib/python3.10/site-packages/robotide/editor/__init__.py", line 64, in enable
    self._show_editor()
  File "/home/tester/.local/lib/python3.10/site-packages/robotide/editor/__init__.py", line 112, in _show_editor
    self.add_tab(self._tab, 'Edit', allow_closing=False)
  File "/home/tester/.local/lib/python3.10/site-packages/robotide/pluginapi/plugin.py", line 241, in add_tab
    self.notebook.add_tab(tab, title, allow_closing)
  File "/home/tester/.local/lib/python3.10/site-packages/robotide/ui/notebook.py", line 54, in add_tab
    self.AddPage(tab, title.strip())
  File "/usr/lib/python3/dist-packages/wx/lib/agw/aui/auibook.py", line 3575, in AddPage
    return self.InsertPage(self.GetPageCount(), page, caption, select, bitmap, disabled_bitmap, control, tooltip)
  File "/usr/lib/python3/dist-packages/wx/lib/agw/aui/auibook.py", line 3653, in InsertPage
    self.SetSelectionToWindow(page)
  File "/usr/lib/python3/dist-packages/wx/lib/agw/aui/auibook.py", line 4410, in SetSelectionToWindow
    self.SetSelection(idx)
  File "/usr/lib/python3/dist-packages/wx/lib/agw/aui/auibook.py", line 4357, in SetSelection
    ctrl.MakeTabVisible(ctrl_idx, ctrl)
  File "/usr/lib/python3/dist-packages/wx/lib/agw/aui/auibook.py", line 1843, in MakeTabVisible
    if not self.IsTabVisible(tabPage, self.GetTabOffset(), dc, win):
  File "/usr/lib/python3/dist-packages/wx/lib/agw/aui/auibook.py", line 1732, in IsTabVisible
    self.Render(dc, wnd)
  File "/usr/lib/python3/dist-packages/wx/lib/agw/aui/auibook.py", line 1601, in Render
    button.rect = self._art.DrawButton(dc, wnd, button_rect, button, wx.RIGHT)
  File "/usr/lib/python3/dist-packages/wx/lib/agw/aui/tabart.py", line 784, in DrawButton
    rect = wx.Rect(in_rect.x + in_rect.width - bmp.GetWidth(),
TypeError: Rect(): arguments did not match any overloaded call:
  overload 1: too many arguments
  overload 2: argument 2 has unexpected type 'float'
  overload 3: argument 1 has unexpected type 'int'
  overload 4: argument 1 has unexpected type 'int'
  overload 5: argument 1 has unexpected type 'int'
  overload 6: argument 1 has unexpected type 'int'
OnInit returned false, exiting...
Exception ignored in atexit callback: <built-in function _wxPyCleanup>
wx._core.wxAssertionError: C++ assertion "GetEventHandler() == this" failed at ../src/common/wincmn.cpp(477) in ~wxWindowBase(): any pushed event handlers must have been removed
Fatal Python error: PyThreadState_Get: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: finalizing (tstate=0x000055af362a9b00)

Current thread 0x00007f1540187000 (most recent call first):
  <no Python frame>
Extension modules: wx._core, wx._stc, yaml._yaml, wx._html, wx._adv, wx._grid, psutil._psutil_linux, psutil._psutil_posix, apt_pkg (total: 9)

Aborted (core dumped)

I will try some rebbot of the machine, and maybe reinstall RIDE with sudo.

Why don’t we have 4.1.1 for Linux ?

[6604_2.png]
Helio_Guilherme
August 3

First of all, I wanted to use my project (RIDE) in Python 3.10 with a newer
version of wxPython like 4.1.1. But the only available version on Linux is
4.0.7 (in Fedora 36 and Ubuntu 22.0.4).
I am happily using it in Fedora 36 (surprisingly), but today I tried to use
it in Ubuntu, and got this weird error mentioning GIL. Searched the Web and
finally found the meaning of the acronym. I actually found an interesting
blog about a fix for a GIL, here.

Well, this is the output on Ubuntu 22.0.4:

~$ ride.py

Traceback (most recent call last):
File “/home/tester/.local/lib/python3.10/site-packages/robotide/applicatio
n/application.py”, line 77, in OnInit
self._plugin_loader.enable_plugins()
File “/home/tester/.local/lib/python3.10/site-packages/robotide/applicatio
n/pluginloader.py”, line 36, in enable_plugins
p.enable_on_startup()
File “/home/tester/.local/lib/python3.10/site-packages/robotide/applicatio
n/pluginconnector.py”, line 52, in enable_on_startup
self.enable()
File “/home/tester/.local/lib/python3.10/site-packages/robotide/applicatio
n/pluginconnector.py”, line 57, in enable
self._plugin.enable()
File “/home/tester/.local/lib/python3.10/site-packages/robotide/editor/i
nit
.py”, line 64, in enable
self._show_editor()
File “/home/tester/.local/lib/python3.10/site-packages/robotide/editor/i
nit
.py”, line 112, in _show_editor
self.add_tab(self._tab, ‘Edit’, allow_closing=False)
File “/home/tester/.local/lib/python3.10/site-packages/robotide/pluginapi/
plugin.py”, line 241, in add_tab
self.notebook.add_tab(tab, title, allow_closing)
File “/home/tester/.local/lib/python3.10/site-packages/robotide/ui/noteboo
k.py”, line 54, in add_tab
self.AddPage(tab, title.strip())
File “/usr/lib/python3/dist-packages/wx/lib/agw/aui/auibook.py”, line 3575
, in AddPage
return self.InsertPage(self.GetPageCount(), page, caption, select, bitma
p, disabled_bitmap, control, tooltip)
File “/usr/lib/python3/dist-packages/wx/lib/agw/aui/auibook.py”, line 3653
, in InsertPage
self.SetSelectionToWindow(page)
File “/usr/lib/python3/dist-packages/wx/lib/agw/aui/auibook.py”, line 4410
, in SetSelectionToWindow
self.SetSelection(idx)
File “/usr/lib/python3/dist-packages/wx/lib/agw/aui/auibook.py”, line 4357
, in SetSelection
ctrl.MakeTabVisible(ctrl_idx, ctrl)
File “/usr/lib/python3/dist-packages/wx/lib/agw/aui/auibook.py”, line 1843
, in MakeTabVisible
if not self.IsTabVisible(tabPage, self.GetTabOffset(), dc, win):
File “/usr/lib/python3/dist-packages/wx/lib/agw/aui/auibook.py”, line 1732
, in IsTabVisible
self.Render(dc, wnd)
File “/usr/lib/python3/dist-packages/wx/lib/agw/aui/auibook.py”, line 1601
, in Render
button.rect = self._art.DrawButton(dc, wnd, button_rect, button, wx.RIGH
T)
File “/usr/lib/python3/dist-packages/wx/lib/agw/aui/tabart.py”, line 784,
in DrawButton
rect = wx.Rect(in_rect.x + in_rect.width - bmp.GetWidth(),
TypeError: Rect(): arguments did not match any overloaded call:
overload 1: too many arguments
overload 2: argument 2 has unexpected type ‘float’
overload 3: argument 1 has unexpected type ‘int’
overload 4: argument 1 has unexpected type ‘int’
overload 5: argument 1 has unexpected type ‘int’
overload 6: argument 1 has unexpected type ‘int’
OnInit returned false, exiting…
Exception ignored in atexit callback:
wx._core.wxAssertionError: C++ assertion “GetEventHandler() == this” failed
at …/src/common/wincmn.cpp(477) in ~wxWindowBase(): any pushed event handle
rs must have been removed
Fatal Python error: PyThreadState_Get: the function must be called with the
GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: finalizing (tstate=0x000055af362a9b00)

Current thread 0x00007f1540187000 (most recent call first):

Extension modules: wx._core, wx._stc, yaml._yaml, wx._html, wx._adv, wx._gri
d, psutil._psutil_linux, psutil._psutil_posix, apt_pkg (total: 9)

Aborted (core dumped)

You’re seeing a Python 3.10 issue with tabart. I thought I had fixed most
of them, but I guess there are still some left. Can you file an issue
about that?

I’m not sure why you’re seeing a core dump after that traceback, though.
Probably another issue.

I will try some rebbot of the machine, and maybe reinstall RIDE with sudo.

Why don’t we have 4.1.1 for Linux ?

I didn’t package it because it wasn’t based on an ABI-stable wxWidgets.
Now that wxWidgets 3.2.0 is out, I’m looking to package a new version of
wxPython, hopefully a 4.2.0.

Scott

3 Likes

I am seeing this error on Python 3.10.6 with wxPython 4.2.0 on Mac OSX Monterey 12.6.

Update; Same as above but now on OSX Ventura 13.2

Update; Same as above OSX Ventura 13.4.1, Python 3.11, wxPython 4.2.1

Hi @Humberto_Sanchez_II - which error, specifically? There are two in @Helio_Guilherme original message. Or are you seeing both? Better yet, please provide the exact error message you’re seeing. Also, what are you doing when you see the error?

I am seeing the following message when running unit test with wxPython components


Ran 11 tests in 0.002s

OK

Fatal Python error: PyThreadState_Get: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)

Python runtime state: finalizing (tstate=0x0000000104ede740)

Current thread 0x00000002014b5e00 (most recent call first):

Garbage-collecting

Abort trap: 6

What unit tests are you running? We would need a way to reproduce the problem.

Attached is a small zip file that demonstrates the above

use Python 3.11.0 and wxPython 4.2.1

python -m unittest TestEventType

gilerror.zip (5.0 KB)

Thanks. It looks like your test case can be simplified much further just to:

evt = wx.PyEvent()

And then you get the same error when the intepreter shuts down. Now to figure out why.

1 Like

And the answer is ?

Unclear? It seems like there may be some change in Python 3.10 wrt GIL handling, but it’s not clear to me what wxPython’s doing wrong. I’d suggest filing an issue though so we can track it better.

Done. Hopefully, I submitted correctly. I referenced this discussion