Answer the question
In order to leave comments, you need to log in
How to fix a bug with asyncpg pool?
Trying to add records to the database in a loop, the
t.py error appears
import asyncio
import base
async def start():
q = 0
while q < 5:
q += 1
await base.insUrl('link')
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(start())
loop.close()
import asyncpg
pool = asyncpg.create_pool(user='postgres', password= '123456', host='localhost', database='rydu', command_timeout=1500000, max_queries=1500000)
con = pool.acquire()
async def insUrl(url):
try:
await con.execute('INSERT INTO links (link, status) VALUES($1, $2) ', url, 200)
finally:
await pool.release(con)
async def close():
await con.close()
Answer the question
In order to leave comments, you need to log in
1. deal with the basics of asyncio, understand what is and how the event loop, async and await work
2. carefully read the docs, even the examples indicate the correct call to create_pool and acquire
PS without good knowledge of python, you can not climb into asyncio.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question