This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kchen
Recipients kchen
Date 2017-07-27.21:11:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1501189905.94.0.421716043749.issue31062@psf.upfronthosting.co.za>
In-reply-to
Content
File objects generated with socket.makefile and that attempt to use line buffering appear to not actually use line buffering, at least for writing.  In this example, the string does not appear to be written until the flush call.

First, set up a socket:
$ nc -l -U /tmp/foo

Then:

Python 3.6.2 (default, Jul 26 2017, 01:41:27) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
>>> s.connect("/tmp/foo")
>>> f = s.makefile("rw", buffering=1)
>>> f.write("asdf\n")
5
>>> f.flush()

The following patch appears to fix the problem:

--- socket.py.orig	2017-07-25 21:41:39.974554944 -0400
+++ socket.py	2017-07-27 17:02:58.223353418 -0400
@@ -253,7 +253,11 @@
             buffer = io.BufferedWriter(raw, buffering)
         if binary:
             return buffer
-        text = io.TextIOWrapper(buffer, encoding, errors, newline)
+        line_buffering = False
+        if buffering == 1:
+            line_buffering = True
+        text = io.TextIOWrapper(buffer, encoding, errors, newline,
+                                line_buffering)
         text.mode = mode
         return text
History
Date User Action Args
2017-07-27 21:11:45kchensetrecipients: + kchen
2017-07-27 21:11:45kchensetmessageid: <1501189905.94.0.421716043749.issue31062@psf.upfronthosting.co.za>
2017-07-27 21:11:45kchenlinkissue31062 messages
2017-07-27 21:11:45kchencreate