[Python-ideas] make Connections iterable

Nathaniel Smith njs at pobox.com
Tue Jan 9 06:24:58 EST 2018

On Tue, Jan 9, 2018 at 2:07 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Mon, 8 Jan 2018 21:22:56 -0800
> Nathaniel Smith <njs at pobox.com> wrote:
>> The only documented error from multiprocessing.Connection.recv is EOFError,
>> which is basically equivalent to a StopIteration.
> Actually recv() can raise an OSError corresponding to any system-level
> error.
>> I'm surprised that multiprocessing.Connection isn't iterable -- it seems
>> like an obvious oversight.
> What is obvious about making a connection iterable?  It's the first
> time I see someone requesting this.

On the receive side, it's a stream of incoming objects that you fetch
one at a time until you get to the end, probably processed with a loop

while True:
        next_message = conn.recv()
    except EOFError:

Why wouldn't it be iterable?


Nathaniel J. Smith -- https://vorpus.org

More information about the Python-ideas mailing list