Skip to content

Connection.reset fails on Amazon Redshift #29

Closed
@emirot

Description

@emirot

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 ?
import asyncio
import asyncpg

async def connect_to_db():
    pool = await asyncpg.create_pool("postgres://user:pass@localhost:5555/dev",
                                     command_timeout=60)
    conn1 = await pool.acquire()
    conn2 = await pool.acquire()
    return pool, conn1, conn2

async def create_table_a(conn):
    await conn.execute('CREATE TABLE my_schema.mytab_a (a int)')

async def create_table_b(conn):
    await conn.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 connections

Thanks for this library

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions