[Python-ideas] make Connections iterable
njs at pobox.com
Tue Jan 9 11:39:06 EST 2018
On Jan 9, 2018 04:12, "Random832" <random832 at fastmail.com> wrote:
On Tue, Jan 9, 2018, at 05:46, Nick Coghlan wrote:
> If you view them as comparable to subprocess pipes, then it can be
> surprising that they're not iterable when using a line-oriented
> If you instead view them as comparable to socket connections, then the
> lack of iteration support seems equally reasonable.
Sockets are files - there's no fundamental reason a stream socket using a
line-oriented protocol (which is a common enough case), or a datagram
socket, shouldn't be iterable. Why aren't they?
Supporting line iteration on sockets would require adding a whole buffering
layer, which would be a huge change in semantics. Also, due to the way the
BSD socket API works, stream and datagram sockets are the same Python type,
so which one would socket.__next__ assume? (Plus datagrams are a bit messy
anyway; you need to know the protocol's max size before you can call recv.)
I know this was maybe a rhetorical question, but this particular case does
have an answer beyond "we never did it that way before" :-).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas