Thanks for the input. I’m going to put some time into this, I just wonder if in Blender code they are specifying the number of threads to use. I’m worried that even setting Linux Processor Affinity wont change the number of threads spawned within Blender code.
Setting the thread affinity manually is not a great way to manage this, since blender by default will still start the number of threads base on the number of cores detected, if you artificially restrict the affinity of those threads to fewer cores, you’ll get excessive context switches and reduced performance.
Blender has a command line option to limit the number of threads, but once started it cannot be changed through the python api afaik.
-t or --threads <threads>
Use amount of <threads> for rendering and other operations
[1-1024], 0 for systems processor count.
I am running Blender by importing bpy within Python. There are a lot of things I need to do in Blender as Python module before baking and/or rendering.
I also do multiple bakes within the same Python workflow. For example, I might bake for 100 frames, then do something in python, and then add new cloth modifier and bake for another 100 frames or so.
I could do everything in Blender as Python module, save the Blend file and then use python to send shell script similar to blender “myscene.blend -t 8 --background --python myscript.py” or something like that. But this would add some serious complexity to the workflow. It would be harder to track crashes, when the bake has finished, etc…
Is there any way to set number of threads when building Blender as Python module? Or does anyone know if this is something that could be considered adding to Python API?