Skip to content

Multiple Queries in parallel with Gino.status(sql) #742

Answered by fantix
kershnerd asked this question in Q&A
Discussion options

You must be logged in to vote

In your particular case, using threads is not making much sense. asyncio.create_task() is the correct method, but you may want to check the following:

  1. Database locks - make sure the 10 concurrent SQLs don't block each other in the database.
  2. Make sure you have enough database connections for each asyncio.Task. This depends on how you establish the connections and use them:
    1. By default, db = Gino() and await db.set_bind() would create a connection pool of up to 10 connections.
    2. asyncio.create_task() will inherit the connection from the caller's context if any.
    3. Multiple tasks cannot use the same connection at the same time.
    4. Wrap your code with async with db.acquire(): block to ensure it's ex…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fithisux
Comment options

Answer selected by fantix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #742 on December 11, 2020 21:43.