Page MenuHome

Use of deprectated PyEval_ReleaseLock() causes crash when Blender built against Python 3.9.0
Closed, ResolvedPublic


System Information
Operating system: Void Linux, x86_64, Python 3.9.0
Graphics card: Radeon RX 580

Blender Version
Broken: 2.83.6, 2.90.1, with Python 3.9.0
Worked: At least 2.83.6 with Python < 3.9.

Short description of error
In the file source/blender/python/generic/bpy_threads.c, the function BPY_thread_save calls PyThreadState_Swap and, if that function returns null, PyEval_ReleaseLock. The function PyEval_ReleaseLock has been deprecated since Python 3.2. In release versions of Python less than 3.9.0, this seems to be of no concern, but this call will cause a segfault with Python 3.9.0.

The same issue affects gdb when linked against Python 3.9.0; the Fedora project documents a fix the replaces *both* the call to PyThreadState_Swap and PyEval_ReleaseLock with a single call to PyEval_SaveThread. (The Fedora patch actually address two separate issues, one of which is related to acquiring the GIL at the right time. Only the first part of the patch comment and the corresponding *last* part of the patch seem relevant here.)

Exact steps for others to reproduce the error

  1. Compile Blender (apparently even the master branch, but certainly 2.83.6 or 2.90.1) against Python 3.9.0.
  2. Launch Blender.
  3. Create a new file ("General").
  4. Switch to Edit Mode.
  5. Switch to Face Select.
  6. Select a face on the default cube.
  7. Press "e" and attempt to extrude the face.

At this point, Blender crashes with a traceback that implicates PyEval_ReleaseLock.

Recommended Solution
I believe this issue is resolved (and have tested the fix with Blender 2.83.6 and 2.90.1, linked against Python 3.9.0, on Void Linux) by redefining BPY_thread_save in source/blender/python/generic/bpy_threads.c to just call PyEval_SaveThread:

BPy_ThreadStatePtr BPY_thread_save(void)
  PyThreadState *tstate = PyEval_SaveThread();
  return (BPy_ThreadStatePtr)tstate;

I am not a Blender user, but am addressing a Reddit report about the issue.

Event Timeline