No module named '_bpy' when using python multiprocessing?

  • could anyone throw any light on how to avoid ModuleNotFoundError: No module named ‘_bpy’ when using python multiprocessing?

  • I’m calling it from within an addon.

File “c:\blender\2.93\scripts\modules\bpy_init_.py”, line 38, in
from _bpy import (
ModuleNotFoundError: No module named ‘_bpy’

This looks like it’ll fix it:

I wonder if Blender could be doing things better here.

the only problem is , when my addon is initialised, blender has already added it’s paths to the sys.path. What’s the best way to get the sys.paths state before blender has added to it?

Not sure if you still need it, but I was able to work around this issue by checking the process name at the start of the script, as blender itself has ‘MainProcess’ as the process name, but any processes created by multiprocessing have different names, so I use this check to manage the bpy imports so the module is only ever imported by the main process

from multiprocessing import current_process

if current_process().name == 'MainProcess':
    import bpy

The only issue with this is that you cant access the bpy module from another process, but you can use shared memory to share some information back and forth for large calculations