if self._pgconn.pipeline_status:
raise e.ProgrammingError("stream() cannot be used in pipeline mode")
- with self._conn.lock:
- self._conn.wait(self._stream_send_gen(query, params, binary=binary))
- first = True
- while self._conn.wait(self._stream_fetchone_gen(first)):
- # We know that, if we got a result, it has a single row.
- rec: Row = self._tx.load_row(0, self._make_row) # type: ignore
- yield rec
- first = False
+ try:
+ with self._conn.lock:
+ self._conn.wait(self._stream_send_gen(query, params, binary=binary))
+ first = True
+ while self._conn.wait(self._stream_fetchone_gen(first)):
+ # We know that, if we got a result, it has a single row.
+ rec: Row = self._tx.load_row(0, self._make_row) # type: ignore
+ yield rec
+ first = False
+ except e.Error as ex:
+ raise ex.with_traceback(None)
def fetchone(self) -> Optional[Row]:
"""
if self._pgconn.pipeline_status:
raise e.ProgrammingError("stream() cannot be used in pipeline mode")
- async with self._conn.lock:
- await self._conn.wait(self._stream_send_gen(query, params, binary=binary))
- first = True
- while await self._conn.wait(self._stream_fetchone_gen(first)):
- # We know that, if we got a result, it has a single row.
- rec: Row = self._tx.load_row(0, self._make_row) # type: ignore
- yield rec
- first = False
+ try:
+ async with self._conn.lock:
+ await self._conn.wait(
+ self._stream_send_gen(query, params, binary=binary)
+ )
+ first = True
+ while await self._conn.wait(self._stream_fetchone_gen(first)):
+ # We know that, if we got a result, it has a single row.
+ rec: Row = self._tx.load_row(0, self._make_row) # type: ignore
+ yield rec
+ first = False
+ except e.Error as ex:
+ raise ex.with_traceback(None)
async def fetchone(self) -> Optional[Row]:
await self._fetch_pipeline()