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

3 Commits

Author SHA1 Message Date
26ce6e28f2 Check if new threads can be created when determining if multithreading is enabled
concurrent.futures may be available but some functionality may not be available.

To more accurately check whether multithreading is available, attempt to start a new thread using a ThreadPoolExecutor.

numpy.org's REPL (backed by Pyodide which is wasm32-emscripten) allows the module to be imported, but submitting a task (which should start a new thread) fails with a RuntimeError.
2023-12-04 03:19:14 +00:00
ae5f9bad40 Move multithreading utils to fbx_utils_threading.py
This enables it to be used by the fbx2json.py and json2fbx.py scripts.
2023-12-02 22:29:53 +00:00
8f977d1250 FBX IO: Add utility to schedule tasks to run on separate threads
Adds a class intended for processing lots of smaller CPU-bound tasks
that release the GIL. This class allows a function to be wrapped such
that calling the wrapper will schedule the wrapped function to be called
on another thread.

When multithreading is not available on the current system, the function
to wrap is returned instead, resulting in single-threaded execution, so
the calling code doesn't need to be aware of whether multithreading is
available.

The class starts its own threads as needed using a ThreadPoolExecutor
and a context manager is used to wait for its threads to shut down when
exiting the context.

Longer tasks, such as those which are IO related may be more suited to
using a ThreadPoolExecutor directly.

This patch on its own makes no changes to FBX import/export.
2023-11-21 05:40:18 +00:00