FBX IO: Add utility to schedule tasks to run on separate threads #105017
@ -10,14 +10,23 @@ from queue import SimpleQueue
|
|||||||
|
|
||||||
# For debugging/profiling purposes, can be modified at runtime to force single-threaded execution.
|
# For debugging/profiling purposes, can be modified at runtime to force single-threaded execution.
|
||||||
_MULTITHREADING_ENABLED = True
|
_MULTITHREADING_ENABLED = True
|
||||||
|
# The concurrent.futures module may not work or may not be available on WebAssembly platforms wasm32-emscripten and
|
||||||
|
# wasm32-wasi.
|
||||||
try:
|
try:
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
except ModuleNotFoundError:
|
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
|
_MULTITHREADING_ENABLED = False
|
||||||
ThreadPoolExecutor = None
|
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():
|
def get_cpu_count():
|
||||||
|
Loading…
Reference in New Issue
Block a user