MagicStack / MagicStack/asyncpg
Concurrent queries on single connection
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 8.1k
- Fork
- 468
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
* **asyncpg version**: 0.22.0
* **PostgreSQL version**: 13.2
* **Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?**: local PostgreSQL install
* **Python version**: 3.9
* **Platform**: centos
* **Do you use pgbouncer?**: No
* **Did you install asyncpg with pip?**: Yes
* **If you built asyncpg locally, which version of Cython did you use?**:
* **Can the issue be reproduced under both asyncio and
[uvloop](https://github.com/magicstack/uvloop)?**: uvloop
from asyncpg.exceptions import InterfaceError
class CursorIterator:
def __init__(self, connection, prefetch, portal_name):
if prefetch <= 0:
raise InterfaceError("prefetch argument must be greater than zero")
self._connection = connection
self._prefetch = prefetch
self._portal_name = portal_name
self.rows = []
def __aiter__(self):
return self
async def __anext__(self):
if not self.rows:
self.rows = await self._connection.fetch(
f"FETCH {self._prefetch} FROM {self._portal_name}"
)
if self.rows:
return self.rows.pop(0)
raise StopAsyncIteration
class Cursor:
def __init__(self, connection, query, *args, prefetch=None):
self._connection = connection
self._args = args
self._prefetch = prefetch
self._query = query
self._portal_name = connection._get_unique_id("portal")
async def __aenter__(self):
await self._connection.execute(
f"DECLARE {self._portal_name} NO SCROLL CURSOR WITH HOLD FOR {self._query}",
*self._args,
)
prefetch = 50 if self._prefetch is None else self._prefetch
return CursorIterator(self._connection, prefetch, self._portal_name)
async def __aexit__(self, *args):
await self._connection.execute(f"CLOSE {self._portal_name}")
Several queries are run concurrently and I receive the following error. What can I do to fix the problem ?
File "asyncpg/protocol/protocol.pyx", line 321, in query
File "asyncpg/protocol/protocol.pyx", line 684, in asyncpg.protocol.protocol.BaseProtocol._check_state
asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progress
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia leggendo asyncpg/protocol/protocol.pyx intorno a BaseProtocol._check_state e confrontalo con l'esempio fornito di Cursor e concurrent-query. Verifica se la stessa connessione viene usata contemporaneamente e determina il comportamento previsto o l'ambito della documentazione; done deve corrispondere a una riproduzione confermata con una direzione concordata dal maintainer.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- postgresql, python
- Ambito
- databases
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 35/100