I’m trying to get more out of my fast CPU (programming for GPU seems even more complicated to me for now), because when scrambling data from many, many objects in the scene, it takes ages before for my script to finish.
I found a nice introduction video into multiprocessing, but Blender is giving me errors I’m clueless about.
I have only very basic understanding of Python, so go easy on me, thank you!
import time
import multiprocessing
start = time.perf_counter()
def do_something():
print('Sleeping 1 second...')
time.sleep(1)
print('Done Sleeping...')
processes = []
for _ in range(2):
p = multiprocessing.Process(target=do_something)
p.start()
processes.append(p)
for process in processes:
process.join()
finish = time.perf_counter()
print(f'Finished in {round(finish-start, 2)} second(s)')
This gives me following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\Blender Foundation\Blender 4.3\4.3\python\Lib\multiprocessing\spawn.py", line 122, in spawn_main
exitcode = _main(fd, parent_sentinel)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Blender Foundation\Blender 4.3\4.3\python\Lib\multiprocessing\spawn.py", line 131, in _main
prepare(preparation_data)
File "C:\Program Files\Blender Foundation\Blender 4.3\4.3\python\Lib\multiprocessing\spawn.py", line 246, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Program Files\Blender Foundation\Blender 4.3\4.3\python\Lib\multiprocessing\spawn.py", line 297, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen runpy>", line 290, in run_path
Traceback (most recent call last):
File "<frozen runpy>", line 254, in _get_code_from_file
File "<string>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\Blender\\gta_files\\GTA_procedural\\math_v36_added_new_funcs.blend\\multiprocessing test'
File "C:\Program Files\Blender Foundation\Blender 4.3\4.3\python\Lib\multiprocessing\spawn.py", line 122, in spawn_main
exitcode = _main(fd, parent_sentinel)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Blender Foundation\Blender 4.3\4.3\python\Lib\multiprocessing\spawn.py", line 131, in _main
prepare(preparation_data)
File "C:\Program Files\Blender Foundation\Blender 4.3\4.3\python\Lib\multiprocessing\spawn.py", line 246, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Program Files\Blender Foundation\Blender 4.3\4.3\python\Lib\multiprocessing\spawn.py", line 297, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen runpy>", line 290, in run_path
File "<frozen runpy>", line 254, in _get_code_from_file
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\Blender\\gta_files\\GTA_procedural\\math_v36_added_new_funcs.blend\\multiprocessing test'
Finished in 0.08 second(s)