Message299351
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 |
|
Date |
User |
Action |
Args |
2017-07-27 21:11:45 | kchen | set | recipients:
+ kchen |
2017-07-27 21:11:45 | kchen | set | messageid: <1501189905.94.0.421716043749.issue31062@psf.upfronthosting.co.za> |
2017-07-27 21:11:45 | kchen | link | issue31062 messages |
2017-07-27 21:11:45 | kchen | create | |
|