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.
Asked
Active
Viewed 1,938 times
1
-
Multithread program sample using python "Threading" module https://blender.stackexchange.com/questions/176593/animation-nodes-2-freezes-with-python-scriptmultithreading?noredirect=1#comment295976_176593 – srt111 May 06 '20 at 09:47
-
unfortunately "Threading" module only offers co-currency – KJS May 08 '20 at 05:44
1 Answers
6
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.
D. Skarn
- 695
- 4
- 16