]> 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>
Fri, 3 May 2024 11:26:40 +0000 (13:26 +0200)
psycopg/psycopg/generators.py

index 4f2ec878bb9cc70d06c392f884cba07962b9669e..aa01f1d62d952d5f1eead33054d9ae6775bc8a3f 100644 (file)
@@ -293,6 +293,16 @@ def copy_to(pgconn: PGconn, buffer: Buffer) -> PQGen[None]:
     while pgconn.put_copy_data(buffer) == 0:
         yield WAIT_W
 
+    # 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