1
$\begingroup$

I'm trying to use multiprocessing module on Windows to run work in parallel. Problem is that on windows, each thread spawns new instance of Blender. Is there a workaround to this? I'm not looking into having co-currency but real multithreading utilizing cpu cores to run tasks.

$\endgroup$
2
  • $\begingroup$ Multithread program sample using python "Threading" module blender.stackexchange.com/questions/176593/… $\endgroup$
    – srt111
    Commented May 6, 2020 at 9:47
  • $\begingroup$ unfortunately "Threading" module only offers co-currency $\endgroup$
    – KJS
    Commented May 8, 2020 at 5:44

1 Answer 1

6
$\begingroup$

This is more of a general Python question rather than Blender. The problem is that you can't use Threading for real parallelism in CPython (which is what Blender is using, the default Python implementation). You can use multiprocessing for that, by creating another process to just run your function that you want to split between cores. The problem is that multiple processes communication comes with a performance cost, so in some cases, running everything just in a single "thread" happens to be faster.

You can use Cython for doing parallel multithreaded execution by using the 'with nogil:' statement, which turns off the global interpreter lock for encapsulated code. That's what I suggest looking for.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged .