William Jamir
03/01/2024, 9:10 AM@flow
async def myflow(experiment_id: int):
engine = create_async_engine(
url=get_db_url(),
connect_args={
'statement_cache_size': 0,
'prepared_statement_cache_size': 0,
},
)
async with AsyncSession(engine) as session:
await session.get(Experiment, experiment_id)
if __name__ == '__main__':
loop = asyncio.run(myflow(189))
But if I use a task, I got the following error:
RuntimeError: Task <Task pending name='Task-27' coro=<AsyncSession.close() running at /Users/william/.pyenv/versions/myenv/lib/python3.11/site-packages/sqlalchemy/ext/asyncio/session.py:1016> cb=[shield.<locals>._inner_done_callback() at /Users/william/.pyenv/versions/3.11.5/lib/python3.11/asyncio/tasks.py:881]> got Future <Future pending cb=[Protocol._on_waiter_completed()]> attached to a different loop
Full stracktrace on thread.
Should I open a github ticket?William Jamir
03/01/2024, 9:15 AM@task()
async def task_get_experiment_from_db(experiment_id: int, session: AsyncSession) -> Experiment:
experiment = await session.get(Experiment, experiment_id)
return experiment
@flow
async def myflow(experiment_id: int):
engine = create_async_engine(
url=get_db_url(),
connect_args={
'statement_cache_size': 0,
'prepared_statement_cache_size': 0,
},
)
async with AsyncSession(engine) as session:
await task_get_experiment_from_db(experiment_id=experiment_id, session=session)
if __name__ == '__main__':
loop = asyncio.run(myflow(189))
I got this error:William Jamir
03/01/2024, 9:15 AMChris Guidry
03/01/2024, 2:02 PMChris Guidry
03/01/2024, 2:03 PMChristine Chen
04/04/2024, 8:05 PMChris Guidry
04/04/2024, 8:22 PMChristine Chen
04/04/2024, 8:23 PM