This repository has been archived by the owner on Jul 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Add asyncio based driver and related components #167
Labels
enhancement
New feature or request
Comments
What does not work when run within a FastAPI web app:: async def get_from_db(...):
return await db_load
def my_function(...):
result = asyncio.run(get_from_db(...))
return result Error:
What kind of works with the FastAPI: async def _log_result(result: str) -> None:
"""simulates logging asynchronously somewhere"""
print(f'started {result}')
await asyncio.sleep(2)
print(f'finished {result}')
def log_result(result: str, event_loop: asyncio.AbstractEventLoop) -> dict:
task = event_loop.create_task(_log_result(result))
print("scheduled task", task)
return {'result': True} If Hamilton executes this, the |
Implementation here! #171 |
This is completed, needs to be released |
12 tasks
Released as part of 1.10.0 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Is your feature request related to a problem? Please describe.
It is conceivable to want to write Hamilton functions in an async based way.
For example, the data loading functions use asyncio based libraries, or you're making external web requests within a function...
However, Hamilton isn't set up to deal with async based functions when Hamilton itself is being run in an asyncio event loop.
Describe the solution you'd like
Since this is a different context. We should have a different Driver and related components that handle async functions and operating in an async manner. E.g.
async def execute()
should be the driver function that needs to be awaited.E.g. something like this in a fastapi app:
Describe alternatives you've considered
If running Hamilton within an event loop is required:
E.g. From within an fast api app:
If running async functions is required, but Hamilton itself is not being run in an event loop:
asyncio.run()
to wrap that code so Hamilton doesn't need to know about anything asyncio.Additional context
Slack discussion - https://hamilton-opensource.slack.com/archives/C03M33QB4M8/p1659463180270219.
The text was updated successfully, but these errors were encountered: