summaryrefslogtreecommitdiff
path: root/eventlet/support
diff options
context:
space:
mode:
authorJakub Stasiak <jakub@stasiak.at>2016-02-09 02:24:47 +0100
committerJakub Stasiak <jakub@stasiak.at>2016-02-09 11:20:05 +0100
commitb7380fdc70fde26777f4f141da3f01570e870cac (patch)
treede9292ca35265f717b399a3ee09f4de2bc46b6e3 /eventlet/support
parent8a4a1212b2097c6ecca96c81dc355388583ac45d (diff)
downloadeventlet-partial-write-fix-2.tar.gz
wsgi: Fix handling partial writes on Python 3partial-write-fix-2
Closes https://github.com/eventlet/eventlet/issues/295 (in the wsgi module we use a custom writelines implementation now). Those write() calls might write only part of the data (and even if they don't - it's more readable to make sure all data is written explicitly). I changed the test code so that the write() implementation returns the number of characters logged and it cooperates nicely with writeall() now.
Diffstat (limited to 'eventlet/support')
-rw-r--r--eventlet/support/__init__.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/eventlet/support/__init__.py b/eventlet/support/__init__.py
index 4c2b75d..d78ac15 100644
--- a/eventlet/support/__init__.py
+++ b/eventlet/support/__init__.py
@@ -53,3 +53,20 @@ def capture_stderr():
finally:
sys.stderr = original
stream.seek(0)
+
+
+def safe_writelines(fd, to_write):
+ # Standard Python 3 writelines() is not reliable because it doesn't care if it
+ # loses data. See CPython bug report: http://bugs.python.org/issue26292
+ for item in to_write:
+ writeall(fd, item)
+
+
+if six.PY2:
+ def writeall(fd, buf):
+ fd.write(buf)
+else:
+ def writeall(fd, buf):
+ written = 0
+ while written < len(buf):
+ written += fd.write(buf[written:])