Hey guys! Long time no see!š
So I tried using the multiprocessing module! My experiments unexpectedly ended up breaking Blender, causing it to crash every time I tried to launch it. I deleted all add-ons, cleared the entire cache, and even attempted to start Blender in factory startup modeābut nothing worked except for completely uninstalling and reinstalling Blender.š
This might not be entirely correct, but here are some possible reasons why the multiprocessing module didnāt work (based on the error messages I analyzed):
1. Context Access Inside Multiprocessing
- My implementation directly accesses bpy.context.scene inside the worker function (render_task).
- This is a problem because bpy.context is not picklable and cannot be passed to subprocesses.
- Probably Victor just avoided accessing bpy.context inside subprocesses.š¤
2. Possible Use of spawn Instead of fork
- On Windows, multiprocessing defaults to spawn, which creates a new interpreter instance for each worker.
- On Linux/macOS, fork is used instead, which duplicates the process memoryāincluding bpy.
- If Victor ran the script on Linux/macOS, it may have worked due to fork, while on Windows, bpy becomes unavailable in the subprocess. (So I'm wondering if this is trueš§)
3. Worker Function Placement
- Victorās function was defined inside if __name__ == '__main__':, it would prevent Blender from executing multiprocessing code at import time.
- My current code calls multiprocessing.Pool directly, which can cause Blender to recursively launch itself inside subprocesses.š¤Ŗ
4. Blender API Restriction: bpy Must Be Used in the Main Thread
- Blender must be executed in the main thread.
- My function might be spawning new processes that try to access Blenderās Python API, which causes bpy.context.preferences to fail.
Final Decision
At this point, Iām going to pause my attempts to integrate multiprocessing into the add-onābecause I am not ready to keep breaking Blender and reinstalling it every time.š
I also want to avoid causing issues for other users. If I give someone my add-on to test on their PC, I donāt want to accidentally break their Blender too.
Right now, I donāt have enough knowledge (or, honestly, motivation) to dig deeper into fixing this issue. But I wanted to give a heads-up so you can be careful, because something could potentially go wrong. šØš¤£