Especially useful for asynchronous libraries like FastAPI, Discord.py etc.
- SyncInAsync creates a ThreadPoolExecutor (or uses a passed one) to execute these synchronous functions in seperate threads. It also takes the running event loop.
- This execution happens through Async IO's run_in_executor.
- run_in_executor returns a Future object which is then used to return the Future's result.
- This result is the result of your synchronous function!
If max_workers is None or not given, it will default to the number of processors on the machine, multiplied by 5, assuming that ThreadPoolExecutor is often used to overlap I/O instead of CPU work and the number of workers should be higher than the number of workers for ProcessPoolExecutor. concurrent.futures docs
You can check your amount in Python with os.cpu_count()