The Python SDK has so far been using a ThreadPoolExecutor to execute functions concurrently. While this works ok for most synchronous methods, it's causing issues when users are using async methods, particularly those with calls to third-party libraries that may be utilizing the event loop. Since each methods runs within its own thread, it is currently assigned its own event loop via asyncio.run.
This PR refactors the worker so that all async methods are executed within the main event loop instead of its own thread, as the intention of decorating a method with async is likely to place methods within an existing event loop.
The Python SDK has so far been using a
ThreadPoolExecutor
to execute functions concurrently. While this works ok for most synchronous methods, it's causing issues when users are usingasync
methods, particularly those with calls to third-party libraries that may be utilizing the event loop. Since each methods runs within its own thread, it is currently assigned its own event loop viaasyncio.run
.This PR refactors the worker so that all
async
methods are executed within the main event loop instead of its own thread, as the intention of decorating a method withasync
is likely to place methods within an existing event loop.