-
Notifications
You must be signed in to change notification settings - Fork 419
cannot perform operation: another operation is in progress #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I found solution - need use pool with many connections instead only one connection:
Thank you! =) |
Does this occur because the same connection is used to handle multiple transactions with the database? |
My issue with this same error message was due to the fact that you can't use the same pool in different event loops. I had been using a singleton to simplify using my connection pool. That was a bad idea. Now I am using 1 pool per loop with no issues. |
This is how I fixed the issue: Previously I had one session shared among multiple coroutines which made concurrent queries to the database: async def calculate_scores(ids: List):
async with AsyncSession(async_engine) as session:
tasks = [create_task(
calculate_score(id, session)
) for id in ids]
await wait(tasks)
scores = [task.result() for task in tasks]
return scores
async def calculate_score(id, session):
score = (await session.execute(select(Item.score).filter(Item.id == id)).scalar_one_or_none()
return score I fixed it by having one session per co-routine async def calculate_scores(ids: List):
tasks = [create_task(
calculate_score(id)
) for id in ids]
await wait(tasks)
scores = [task.result() for task in tasks]
return mean(score)
async def calculate_score(id):
async with AsyncSession(async_engine) as session:
score = (await session.execute(select(Item.score).filter(Item.id == id)).scalar_one_or_none()
return score |
Hope someone will see this message? Why I must use connection pool to perform multiple operations at the same time? I understand if I use same connection for serveral read and write queries, then I can not support consistency of results, since I do not know before hand how long it takes to execute a query. However if I have read only queries, there is no problem with consistency and race conditions. I can not use single query to fetch several tables(i think I can but that is much more complicated, than few simple select queries. Is there any plans to allow concurrent queries with the same connection? Or is it constraint from postgres(or even overall databases) side? |
the issue with a local PostgreSQL install?:
uvloop?:
Hi! I want make db queries in different async tasks, but then i try, i got this:
Code to reproduce that:
Please, can you help?
The text was updated successfully, but these errors were encountered: