From: Andrew Kane Date: Mon, 4 Mar 2024 22:34:56 +0000 (-0800) Subject: Improve performance of copy X-Git-Tag: 3.2.0~36^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5409e424986f2aea180a45faf6d46780b2deadac;p=thirdparty%2Fpsycopg.git Improve performance of copy --- diff --git a/psycopg/psycopg/generators.py b/psycopg/psycopg/generators.py index 489c9bb32..f25e6a168 100644 --- a/psycopg/psycopg/generators.py +++ b/psycopg/psycopg/generators.py @@ -346,6 +346,16 @@ def copy_to(pgconn: PGconn, buffer: Buffer) -> PQGen[None]: if ready: break + # Repeat until it the message is flushed to the server + while True: + while True: + ready = yield WAIT_W + if ready: + break + f = pgconn.flush() + if f == 0: + break + def copy_end(pgconn: PGconn, error: Optional[bytes]) -> PQGen[PGresult]: # Retry enqueuing end copy message until successful