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 martin.panter
Recipients martin.panter
Date 2016-04-09.12:19:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This is a follow-on from Issue 24291. Currently, for stream servers (as opposed to datagram servers), the wfile attribute is a raw SocketIO object. This means that wfile.write() is a simple wrapper around socket.send(), and can do partial writes.

There is a comment inherited from Python 2 that reads:

# . . . we make
# wfile unbuffered because (a) often after a write() we want to
# read and we need to flush the line; (b) big writes to unbuffered
# files are typically optimized by stdio even when big reads
# aren't.

Python 2 only has one kind of “file” object, and it seems partial writes are impossible: <>. But in Python 3, unbuffered mode means that the lower-level RawIOBase API is involved rather than the higher-level BufferedIOBase API.

I propose to change the “wfile” attribute to be a BufferedIOBase object, yet still be “unbuffered”. This could be implemented with a class that looks something like

class _SocketWriter(BufferedIOBase):
    """Simple writable BufferedIOBase implementation for a socket
    Does not hold data in a buffer, avoiding any need to call flush()."""
    def write(self, b):
        return len(b)
Date User Action Args
2016-04-09 12:19:55martin.pantersetrecipients: + martin.panter
2016-04-09 12:19:55martin.pantersetmessageid: <>
2016-04-09 12:19:55martin.panterlinkissue26721 messages
2016-04-09 12:19:55martin.pantercreate