hatchet-dev / hatchet-python

Hatchet Python SDK for Interacting with the Hatchet Engine
10 stars 4 forks source link

fix: allow async functions to execute in the main event loop #24

Closed abelanger5 closed 1 month ago

abelanger5 commented 1 month ago

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.