- Notifications
You must be signed in to change notification settings - Fork 437
Closed
Labels
Description
Let's say I have two long running queries that I'd like to run concurrently
Here is my questions :
- Does asyncpg will help in that case ?
- using concurrent.futures will do the same ?
importasyncioimportasyncpgasyncdefconnect_to_db(): pool=awaitasyncpg.create_pool("postgres://user:pass@localhost:5555/dev", command_timeout=60) conn1=awaitpool.acquire() conn2=awaitpool.acquire() returnpool, conn1, conn2asyncdefcreate_table_a(conn): awaitconn.execute('CREATE TABLE my_schema.mytab_a (a int)') asyncdefcreate_table_b(conn): awaitconn.execute('CREATE TABLE my_schema.mytab_b (b int)') loop=asyncio.get_event_loop() pool, conn1, conn2=loop.run_until_complete(connect_to_db()) tasks= [asyncio.ensure_future(create_table_a(conn1)), asyncio.ensure_future(create_table_b(conn2))] loop.run_until_complete(asyncio.wait(tasks)) #release the pool and the connectionsThanks for this library