]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Improve performance of copy
authorAndrew Kane <andrew@ankane.org>
Mon, 4 Mar 2024 22:34:56 +0000 (14:34 -0800)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 8 May 2024 09:56:15 +0000 (11:56 +0200)
psycopg/psycopg/generators.py

index 489c9bb3216b93e50a0e284c4259ca5f91f075c8..f25e6a1682921c32b8c96ee722f8089e3aec5a2b 100644 (file)
@@ -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