Standalone bpy
module crashes Python on exit
#125376
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#125376
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
Operating system: macOS-14.5-arm64-arm-64bit 64 Bits
Graphics card: Metal API Apple M2 Pro 1.2
Blender Version
Broken:
fd4fb94751d100af967cf0b2743a1fbf33a6fc8f
Worked:
4.2.0
Short description of error
Using the standalone
bpy
python module can crash Python on exit because the PyModuleDef.m_free handler is not invoked.Exact steps for others to reproduce the error
Blender keeps a static list of
SpaceType
instances in get_space_types()Normally these are cleaned up in
BKE_spacetypes_free()
which is called from thebpy
PyModuleDef.m_free handler.In some cases, this
m_free
handler is not called at all and so theget_space_types()
instances are automatically destructed at program exit, as part of their destruction they call into the python interpreter (PyGILState_Ensure()
) and this crashes because the interpreter has already been torn down earlier.A non-crashing example is:
We can see the static
SpaceType
s are destroyed normally from thePyModuleDef.m_free
callback (bpy_module_free
):A crashing example is:
We can see the static
SpaceType
s are destroyed as the process exits - and this crashes since the Python interpreter has already been torn down earlier:Also running each of the above examples with
python -v
(which logs module initialization and destruction), we can see the non-crashing example logs:and the crashing example logs:
i.e. it is completely missing destroying the
bpy
module. The "# destroy ..." are logged from module_dealloc() and that is also wherem_free
is invoked. So Python is never deallocing thebpy
module nor invoking it'sm_free
.I
git bisect
ed and this started happening with this commitIt's not clear how that would cause this though.
Declaring generic Python type crashes bpy on exitto Standalone `bpy` module crashes Python on exit@ideasman42 Can you check?
Cannot repro on linux in
884d882155
(dont have my MAC with me today, but could this possibly be a MAC-only issue?)I suspect it could be (or at least my sample reproduces on macos, there may be other cases that repro on linux). The commit that triggered this enabled audaspace with standalone bpy, and the audio systems stuff is quite different on linux than mac.
I just tried with
488b5cda54
and am still able to repro on macos:This crash is similar to that seen in #126807
Something weird is happening, somehow, with the
typing
module indeed.The problem is somehow
bpy
module has one additional refcount (3 instead of 2) at finalization time, and so normally it ends up being decref'd and freed (bpy_module_free
ends up callingBKE_spacetypes_free
to free that static global list). But in this case it still has a ref and so we don'tbpy_module_free
, and so the staticSpaceType
list is freed at exit which is after the python interpreter has already shut down, and part of freeing that list attempts to call back into python which asserts/crashes.I tried comparing the behavior before and after commit
fd4fb94751
- but I couldn't figure out where that additional reference onbpy
was coming from.If you run
python -v
so it logs module import/cleanup and grepbpy
you can see the non-crashing version logs an additionaldestroy bpy
when the python interpreter destroys the module, in the crashing case it is never destroyed: