asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progress
See original GitHub issueHi, here is my code ,please help resovle the problem.thanks a lot.
from sanic import Sanic
from sanic.response import json
import asyncpg
import asyncio
import uvloop
loop = uvloop.new_event_loop()
app = Sanic()
app.debug = True
async def initdb_pool():
dbdict = {"database":"mqtt","user":"mqtt","password":"mqtt123",
"host":"192.168.25.100","port":5433}
return await asyncpg.create_pool(**dbdict)
@app.route("/iot/v1.0/app/auth/<user:[A-z0-9]\w+>/<pwd:[A-z0-9]\w+>/")
async def applogin(request,user,pwd):
async with engine.acquire() as connection:
#async with connection.transaction():
stmt = await connection.prepare('select key from user_manager_appuser where uname = $1 or email = $2 or phone = $3')
result = await stmt.fetchval(user,user,user)
# result = await connection.fetchval('select key from user_manager_appuser where uname = $1 or email = $2 or phone = $3',
# user,user,user)
if not result:
return json({'ok':False,'err':'Pwd error'})
print("result is ",result)
return json({'ok':True,'data':str(result)})
if __name__ == "__main__":
engine = loop.run_until_complete(initdb_pool())
app.run(host="0.0.0.0",port=8000,debug=True)
curl "http://127.0.0.1:8000/iot/v1.0/app/auth/abc/123456/"
Error: cannot perform operation: another operation is in progress
Exception: Traceback (most recent call last):
File "/media/yjdwbj/E/py360dev/lib/python3.6/site-packages/sanic/sanic.py", line 194, in handle_request
response = await response
File "/opt/python360/lib/python3.6/asyncio/coroutines.py", line 128, in throw
return self.gen.throw(type, value, traceback)
File "main.py", line 32, in applogin
return json({'ok':True,'data':str(result)})
File "/opt/python360/lib/python3.6/asyncio/coroutines.py", line 109, in __next__
return self.gen.send(None)
File "/media/yjdwbj/E/py360dev/lib/python3.6/site-packages/asyncpg/pool.py", line 252, in __aexit__
await self.pool.release(con)
File "/opt/python360/lib/python3.6/asyncio/coroutines.py", line 109, in __next__
return self.gen.send(None)
File "/media/yjdwbj/E/py360dev/lib/python3.6/site-packages/asyncpg/pool.py", line 184, in release
await connection.reset()
File "/opt/python360/lib/python3.6/asyncio/coroutines.py", line 109, in __next__
return self.gen.send(None)
File "/media/yjdwbj/E/py360dev/lib/python3.6/site-packages/asyncpg/connection.py", line 411, in reset
''')
File "/opt/python360/lib/python3.6/asyncio/coroutines.py", line 109, in __next__
return self.gen.send(None)
File "/media/yjdwbj/E/py360dev/lib/python3.6/site-packages/asyncpg/connection.py", line 170, in execute
return await self._protocol.query(query, timeout)
File "asyncpg/protocol/protocol.pyx", line 247, in query (asyncpg/protocol/protocol.c:51830)
File "asyncpg/protocol/protocol.pyx", line 352, in asyncpg.protocol.protocol.BaseProtocol._ensure_clear_state (asyncpg/protocol/protocol.c:54136)
asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progress
Issue Analytics
- State:
- Created 7 years ago
- Comments:22 (3 by maintainers)
Top Results From Across the Web
asyncpg - another operation is in progress - Stack Overflow
I am attempting to resolve the following error: asyncpg.exceptions._base.InterfaceError: cannot perform operation ...
Read more >cannot perform operation: another operation is in progress #258
asyncpg version: 0.14.0 PostgreSQL version: Postgres in docker, ... test.py:15> exception=InterfaceError('cannot perform operation: another ...
Read more >r/Python - SQLAlchemy with asyncpg cannot perform operation
InterfaceError ) <class 'asyncpg.exceptions._base.InterfaceError'>: cannot perform operation: another operation is in progress.
Read more >Source code for asyncpg.connection
Specifically, we want to make the following # operation atomic: ... This method can execute many SQL commands at once, when no arguments...
Read more >Pytest+FastAPI+SQLAlchemy+Postgres InterfaceError
The basic error is sqlalchemy.exc.InterfaceError('cannot perform operation: another operation is in progress') . This may be related to the app/DB ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Behzad-S seems like you are using a shared connection and are attempting to run queries concurrently on it. Use
asyncpg.Pooland acquire/release a connection for each request.I fixed it by setting poolclass=NullPool in create_async_engine