FBX IO: Add utility to schedule tasks to run on separate threads #105017

Merged
Thomas Barlow merged 3 commits from Mysteryem/blender-addons:fbx_multithread_utils_pr into main 2024-01-12 21:29:22 +01:00
Showing only changes of commit 26ce6e28f2 - Show all commits

View File

@ -10,14 +10,23 @@ from queue import SimpleQueue
# For debugging/profiling purposes, can be modified at runtime to force single-threaded execution.
_MULTITHREADING_ENABLED = True
# The concurrent.futures module may not work or may not be available on WebAssembly platforms wasm32-emscripten and
# wasm32-wasi.
try:
from concurrent.futures import ThreadPoolExecutor
except ModuleNotFoundError:
# The concurrent.futures module does not work or is not available on WebAssembly platforms wasm32-emscripten
# and wasm32-wasi.
# wasm32-emscripten raises ModuleNotFoundError, not sure about wasm32-wasi.
_MULTITHREADING_ENABLED = False
ThreadPoolExecutor = None
else:
try:
# The module may be available, but not be fully functional. An error may be raised when attempting to start a
# new thread.
with ThreadPoolExecutor() as tpe:
# Attempt to start a thread by submitting a callable.
tpe.submit(lambda: None)
except Exception:
# Assume that multithreading is not supported and fall back to single-threaded execution.
_MULTITHREADING_ENABLED = False
def get_cpu_count():