Re: [Python-ideas] make Connections iterable

2018-01-09 Thread Antoine Pitrou
On Tue, 9 Jan 2018 08:39:06 -0800 Nathaniel Smith wrote: > On Jan 9, 2018 04:12, "Random832" 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 >

Re: [Python-ideas] make Connections iterable

2018-01-09 Thread Ethan Furman
On 01/09/2018 08:27 AM, Chris Angelico wrote: On Tue, Jan 9, 2018 at 11:12 PM, Random832 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 protocol. If yo

Re: [Python-ideas] make Connections iterable

2018-01-09 Thread Nathaniel Smith
On Jan 9, 2018 04:12, "Random832" 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 > protocol. > > If you instead view them as comparable to socket conne

Re: [Python-ideas] make Connections iterable

2018-01-09 Thread Chris Angelico
On Tue, Jan 9, 2018 at 11:12 PM, Random832 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 >> protocol. >> >> If you instead view them as comparable

Re: [Python-ideas] make Connections iterable

2018-01-09 Thread Serhiy Storchaka
09.01.18 12:46, Nick Coghlan пише: On 9 January 2018 at 20:07, Antoine Pitrou wrote: On Mon, 8 Jan 2018 21:22:56 -0800 Nathaniel Smith wrote: I'm surprised that multiprocessing.Connection isn't iterable -- it seems like an obvious oversight. What is obvious about making a connection iterabl

Re: [Python-ideas] make Connections iterable

2018-01-09 Thread Random832
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 > protocol. > > If you instead view them as comparable to socket connections, then the > lack of iteration suppo

Re: [Python-ideas] make Connections iterable

2018-01-09 Thread Nathaniel Smith
On Tue, Jan 9, 2018 at 2:07 AM, Antoine Pitrou wrote: > On Mon, 8 Jan 2018 21:22:56 -0800 > Nathaniel Smith wrote: >> >> The only documented error from multiprocessing.Connection.recv is EOFError, >> which is basically equivalent to a StopIteration. > > Actually recv() can raise an OSError corres

Re: [Python-ideas] make Connections iterable

2018-01-09 Thread Antoine Pitrou
On Tue, 9 Jan 2018 20:46:35 +1000 Nick Coghlan wrote: > On 9 January 2018 at 20:07, Antoine Pitrou wrote: > > On Mon, 8 Jan 2018 21:22:56 -0800 > > Nathaniel Smith wrote: > >> I'm surprised that multiprocessing.Connection isn't iterable -- it seems > >> like an obvious oversight. > > > > Wha

Re: [Python-ideas] make Connections iterable

2018-01-09 Thread Nick Coghlan
On 9 January 2018 at 20:07, Antoine Pitrou wrote: > On Mon, 8 Jan 2018 21:22:56 -0800 > Nathaniel Smith wrote: >> 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

Re: [Python-ideas] make Connections iterable

2018-01-09 Thread Antoine Pitrou
On Mon, 8 Jan 2018 21:22:56 -0800 Nathaniel Smith 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 multipr

Re: [Python-ideas] make Connections iterable

2018-01-08 Thread Nathaniel Smith
On Mon, Jan 8, 2018 at 7:27 PM, Amit Green wrote: > An argument against this API, is that any caller of recv should be doing > error handling (i.e.: catching exceptions from the socket). > It's still not entirely clear, but I'm pretty sure this thread is talking about multiprocessing.Connection

Re: [Python-ideas] make Connections iterable

2018-01-08 Thread Amit Green
On Mon, Jan 8, 2018 at 10:34 PM, Nick Coghlan wrote > It could be useful to include a recipe in the documentation that shows a > generator with suitable error handling (taking the generic connection > errors and adapting them to app specific ones) while also showing how to > adapt the connection

Re: [Python-ideas] make Connections iterable

2018-01-08 Thread Nick Coghlan
On 9 January 2018 at 13:27, Amit Green wrote: > An argument against this API, is that any caller of recv should be doing > error handling (i.e.: catching exceptions from the socket). > > Changing into an iterator makes it less likely that error handling will be > properly coded, and makes the err

Re: [Python-ideas] make Connections iterable

2018-01-08 Thread Amit Green
An argument against this API, is that any caller of recv should be doing error handling (i.e.: catching exceptions from the socket). Changing into an iterator makes it less likely that error handling will be properly coded, and makes the error handling more obscure. Thus although the API would ma

Re: [Python-ideas] make Connections iterable

2018-01-08 Thread Oscar Smith
The arguments for including this API is that it allows easy iteration over the results of a connection allowing it to be used with any of the features of itertools or any other library accepting iterables. recv is only used in places where the iterable protocol could be used, so it makes sense for

Re: [Python-ideas] make Connections iterable

2018-01-08 Thread Steven D'Aprano
On Mon, Jan 08, 2018 at 10:17:30AM -0600, Oscar Smith wrote: > I am currently working on a program where it would be really useful if a > connection had a __next__ method, because then it would be much easier to > iterate over. What sort of connection are you referring to? > It would just be an

Re: [Python-ideas] make Connections iterable

2018-01-08 Thread Terry Reedy
On 1/8/2018 11:17 AM, Oscar Smith wrote: I am currently working on a program where it would be really useful if a connection had a __next__ method, because then it would be much easier to iterate over. It would just be an alias to recv, but would allow you > to do things like merging the resul