Using bpy
module with multiprocessing
causes ModuleNotFoundError: No module named '_bpy'
#98534
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
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
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
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
EEVEE & Viewport
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
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
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
9 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#98534
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
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 Monterey (12.4)
Graphics card: M1 Pro
Blender Version
Broken: 3.1
Worked: -
Hello,
I'm using Blender through the
bpy
module and I noticed usingbpy
module withmultiprocessing
causes a ModuleNotFoundError error. I just wanted to draw Blender developers attention to this bug.How to reproduce the crash
Create
bug.py
with this content, and runpython3 bug.py
:You will get the following traceback:
Why does it happen?
A few discussion/threads have already touched on this issue and here is a summary from here nicely describing why this error happens in essence:
Hacky Workarounds
I also found a couple of hacky workarounds:
sys.path
beforeimport bpy
. And restore it right before instantiating the multiprocessing object. Once done, revert your change. Code, orimport bpy
to avoid re-importing it:Added subscriber: @emadpres
Added subscriber: @ideasman42
Changed status from 'Needs Triage' to: 'Needs User Info'
Thanks for the detailed description of the error. If I understand this correctly the error is caused by there being two
bpy
modules../bpy.so
./3.3/scripts/modules/bpy/__init__.py
Once C/Python module is loaded, spawned subprocesses find the second one which has not loaded the C/Python module
_bpy
whichbpy.so
defines.There are probably a few ways to resolve this, although I'm currently unable to reproduce the bug, the example code provided loads the Blender module and exists, tested with a build from running:
make bpy lite
.Could you show an example that spawns processes that attempt to use the bpy module?
Hi Campbell and thanks for your following up. I used
make bpy
to build the Blender module. The error happens on my mac (arm64), but not on my ubuntu machine. Are you on macOS or other operating systems?@emadpres I'm using Arch Linux, it seems this may be spesific to macOS.
@ideasman42 Yes, it is specific to macOS. It doesn't occur in Ubuntu for me.
Any update on the issue?
Added subscriber: @Alexander-Hartmann
This comment was removed by @Alexander-Hartmann
@Alexander-Hartmann, as this isn't related to
multiprocessing
module, best make a new report.ok deleted, until ##multiprocessing## I could not run yet
Added subscriber: @timodriaan
Changed status from 'Needs User Info' to: 'Needs Triage'
Removed subscriber: @Alexander-Hartmann
Added subscriber: @muhuk
Added subscriber: @TobiaszunfaKaron
It seems I am having the same problem on Windows 10.
When using Grid UV Packer in Blender 3.4.1 it seems to freeze blender with this console output:
It seems OS-specific because multiprocessing uses the "spawn" start method on MacOS and Windows, and "fork" as default on Linux. This problem occurs only if the start method is set to "spawn". Although everything seems to work nicely with the fork, I need the spawn method to initialize the CUDA context in subprocesses, as of Blender 3.6 it still doesn't work.
Note that you cant set the "fork" start method in non-Linux operating systems as it is not supported.