Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
yield from multiple iterables (was Re: The async API of the future: yield-from)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 76 - 100 of 112 - Collapse all  -  Translate all to Translated (View all originals) < Older  Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Guido van Rossum  
View profile  
 More options Oct 22 2012, 4:59 pm
From: Guido van Rossum <gu...@python.org>
Date: Mon, 22 Oct 2012 13:58:14 -0700
Local: Mon, Oct 22 2012 4:58 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)
Steve, I realize that continued point-by-point rebuttals probably are
getting pointless. Maybe your enthusiasm and energy would be better
spent trying to propose and implement (a prototype) of an API in the
style that you prefer? Maybe we can battle it out in code more
easily...

--
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Dower  
View profile  
 More options Oct 22 2012, 5:34 pm
From: Steve Dower <Steve.Do...@microsoft.com>
Date: Mon, 22 Oct 2012 21:32:42 +0000
Local: Mon, Oct 22 2012 5:32 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)
Sounds good. I'll make some revisions to the code I posted earlier and come up with some comparable/benchmarkable examples.

Apart from the network server and client examples that have already been discussed, any particular problems I should be looking at solving with this? (Anyone?) I don't want to only come up with 'good' examples.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guido van Rossum  
View profile  
 More options Oct 22 2012, 5:45 pm
From: Guido van Rossum <gu...@python.org>
Date: Mon, 22 Oct 2012 14:41:55 -0700
Local: Mon, Oct 22 2012 5:41 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

On Mon, Oct 22, 2012 at 2:32 PM, Steve Dower <Steve.Do...@microsoft.com> wrote:
> Sounds good. I'll make some revisions to the code I posted earlier and come up with some comparable/benchmarkable examples.

> Apart from the network server and client examples that have already been discussed, any particular problems I should be looking at solving with this? (Anyone?) I don't want to only come up with 'good' examples.

I have a prototype implementing an async web client that fetches a
page given a URL. Primitives I have in mind include running several of
these concurrently and waiting for the first to come up with a result,
or waiting for all results, or getting the results as they are ready.
I have an event loop that can use select, poll, epoll, and kqueue
(though I've only lightly tested it, on Linux and OSX, so I'm sure
I've missed some corner cases and optimization possibilities). The
fetcher calls socket.getaddrinfo() in a threadpool.

--
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Greg Ewing  
View profile  
 More options Oct 22 2012, 6:14 pm
From: Greg Ewing <greg.ew...@canterbury.ac.nz>
Date: Tue, 23 Oct 2012 11:09:41 +1300
Local: Mon, Oct 22 2012 6:09 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

Guido van Rossum wrote:
> On Mon, Oct 22, 2012 at 8:55 AM, Steve Dower <Steve.Do...@microsoft.com> wrote:
>> Yes, but unless you run all subsequent code on the IOCP thread (thereby
>> blocking any more completions) you need to schedule it back to another thread.
>> This requires synchronization.

I think there's an assumption behind this whole async tasks discussion
that the tasks being scheduled are I/O bound. We're trying to overlap
CPU activity with I/O, and different I/O activities with each other.
We're *not* trying to achieve concurrency of CPU-bound tasks -- the
GIL prevents that anyway for pure Python code.

The whole Windows IOCP thing, on the other hand, seems to be geared
towards having a pool of threads, any of which can handle any I/O
operation. That's not helpful for us; when one of our tasks blocks
waiting for I/O, the completion of that I/O must wake up *that particular
task*, and it must be run using the same OS thread that was running
it before.

I gather that Windows provides a way of making an async I/O request
and specifying a callback for that request. If that's the case, do
we need to bother with an IOCP at all? Just have the callback wake
up the associated task directly.

--
Greg
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guido van Rossum  
View profile  
 More options Oct 22 2012, 6:31 pm
From: Guido van Rossum <gu...@python.org>
Date: Mon, 22 Oct 2012 15:30:46 -0700
Local: Mon, Oct 22 2012 6:30 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

On Mon, Oct 22, 2012 at 3:09 PM, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
> I think there's an assumption behind this whole async tasks discussion
> that the tasks being scheduled are I/O bound. We're trying to overlap
> CPU activity with I/O, and different I/O activities with each other.
> We're *not* trying to achieve concurrency of CPU-bound tasks -- the
> GIL prevents that anyway for pure Python code.

Right. Of course.

> The whole Windows IOCP thing, on the other hand, seems to be geared
> towards having a pool of threads, any of which can handle any I/O
> operation. That's not helpful for us; when one of our tasks blocks
> waiting for I/O, the completion of that I/O must wake up *that particular
> task*, and it must be run using the same OS thread that was running
> it before.

The reason we can't ignore IOCP is that it is apparently the *only*
way to do async I/O in a scalable way. The only other polling
primitive available is select() which does not scale. (Or so it is
asserted by many folks; I haven't tested this, but I believe the
argument against select() scaling in general.)

> I gather that Windows provides a way of making an async I/O request
> and specifying a callback for that request. If that's the case, do
> we need to bother with an IOCP at all? Just have the callback wake
> up the associated task directly.

AFAICT the way to do that goes through IOCP...

--
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Greg Ewing  
View profile  
 More options Oct 22 2012, 6:33 pm
From: Greg Ewing <greg.ew...@canterbury.ac.nz>
Date: Tue, 23 Oct 2012 11:33:00 +1300
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

Guido van Rossum wrote:
> (Aside: please don't use 'continuation' for 'task'. The use of this
> term in Scheme has forever tainted the word for me.)

It has a broader meaning than the one in Scheme; essentially
it's a synonym for "callback".

I agree it shouldn't be used as a synonym for "task", though.
In any of its forms, a continuation isn't an entire task, it's
something that you call to cause the resumption of a task
from a particular suspension point.

--
Greg
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Dower  
View profile  
 More options Oct 22 2012, 6:37 pm
From: Steve Dower <Steve.Do...@microsoft.com>
Date: Mon, 22 Oct 2012 22:31:10 +0000
Local: Mon, Oct 22 2012 6:31 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

>>> Yes, but unless you run all subsequent code on the IOCP thread
>>> (thereby blocking any more completions) you need to schedule it back to another thread.
>>> This requires synchronization.

> I think there's an assumption behind this whole async tasks discussion that the tasks
> being scheduled are I/O bound. We're trying to overlap CPU activity with I/O, and
> different I/O activities with each other.
> We're *not* trying to achieve concurrency of CPU-bound tasks -- the GIL prevents that
> anyway for pure Python code.

Sure, but it's easy enough to slip it in for (nearly) free. The only other option is complete exclusion of CPU-bound concurrency, which also rules out running C functions (outside the GIL) on a separate thread.

> The whole Windows IOCP thing, on the other hand, seems to be geared towards having a pool
> of threads, any of which can handle any I/O operation. That's not helpful for us; when one
> of our tasks blocks waiting for I/O, the completion of that I/O must wake up *that
> particular task*, and it must be run using the same OS thread that was running it before.

> I gather that Windows provides a way of making an async I/O request and specifying a
> callback for that request. If that's the case, do we need to bother with an IOCP at all?
> Just have the callback wake up the associated task directly.

IOCP is probably not useful at all, and as Guido said, it was brought up as an example of a non-select style of waiting. APIs like ReadFileEx/WriteFileEx let you provide the callback directly without using IOCP. In any case, even if we did use IOCP it would be an implementation detail and would not affect how the API is exposed.

(Also, love your work on PEP 380. Despite my hesitation about using yield from for this API, I do really like using it with generators.)

Cheers,
Steve

_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guido van Rossum  
View profile  
 More options Oct 22 2012, 6:38 pm
From: Guido van Rossum <gu...@python.org>
Date: Mon, 22 Oct 2012 15:35:12 -0700
Local: Mon, Oct 22 2012 6:35 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

On Mon, Oct 22, 2012 at 3:33 PM, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
> Guido van Rossum wrote:

>> (Aside: please don't use 'continuation' for 'task'. The use of this
>> term in Scheme has forever tainted the word for me.)

> It has a broader meaning than the one in Scheme; essentially
> it's a synonym for "callback".

(Off-topic:) But does that meaning apply to Scheme? If so, I wish
someone would have told me 15 years ago...

> I agree it shouldn't be used as a synonym for "task", though.
> In any of its forms, a continuation isn't an entire task, it's
> something that you call to cause the resumption of a task
> from a particular suspension point.

I guess that was just Steve showing off. :-)

--
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Dower  
View profile  
 More options Oct 22 2012, 6:50 pm
From: Steve Dower <Steve.Do...@microsoft.com>
Date: Mon, 22 Oct 2012 22:49:40 +0000
Local: Mon, Oct 22 2012 6:49 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)
Alertable I/O (<http://msdn.microsoft.com/en-us/library/windows/desktop/aa363772.aspx>) and overlapped I/O are two alternatives to IOCP on Windows.

>> I agree [continuation] shouldn't be used as a synonym for "task", though.
>> In any of its forms, a continuation isn't an entire task, it's
>> something that you call to cause the resumption of a task
>> from a particular suspension point.

> I guess that was just Steve showing off. :-)

Not intentionally - the team here that did async/await in C# talks a lot about "continuation-passing style", which is where I picked the term up from. I don't use it as a synonym for "task" - it's always meant the "bit that runs after we come back from the yield" (hmm... I think that definition needs some work...).

_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guido van Rossum  
View profile  
 More options Oct 22 2012, 6:57 pm
From: Guido van Rossum <gu...@python.org>
Date: Mon, 22 Oct 2012 15:56:48 -0700
Local: Mon, Oct 22 2012 6:56 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

On Mon, Oct 22, 2012 at 3:49 PM, Steve Dower <Steve.Do...@microsoft.com> wrote:
> Alertable I/O (<http://msdn.microsoft.com/en-us/library/windows/desktop/aa363772.aspx>) and overlapped I/O are two alternatives to IOCP on Windows.

>>> I agree [continuation] shouldn't be used as a synonym for "task", though.
>>> In any of its forms, a continuation isn't an entire task, it's
>>> something that you call to cause the resumption of a task
>>> from a particular suspension point.

>> I guess that was just Steve showing off. :-)

> Not intentionally - the team here that did async/await in C# talks a lot about "continuation-passing style", which is where I picked the term up from. I don't use it as a synonym for "task" - it's always meant the "bit that runs after we come back from the yield" (hmm... I think that definition needs some work...).

Yeah, I have the same terminology hang-up with the term
"continuation-passing-style" for web callbacks.

Reading back what you wrote, you were indeed trying to distinguish
between the "callback" (which you consider the thing that's directly
invoked by the OS) and "the rest of the task" (e.g. the code that runs
when the yield is resumed), which you were referring to as
"continuation". I'd just use "the rest of the task" here.

--
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Greg Ewing  
View profile  
 More options Oct 22 2012, 7:05 pm
From: Greg Ewing <greg.ew...@canterbury.ac.nz>
Date: Tue, 23 Oct 2012 12:04:57 +1300
Local: Mon, Oct 22 2012 7:04 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

Guido van Rossum wrote:
> The reason we can't ignore IOCP is that it is apparently the *only*
> way to do async I/O in a scalable way. The only other polling
> primitive available is select() which does not scale.

There seems to be an alternative to polling, though. There are
functions called ReadFileEx and WriteFileEx that allow you to
pass in a routine to be called when the operation completes:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365468%28v=...
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365748%28v=...

Is there some reason that this doesn't scale either?

--
Greg
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guido van Rossum  
View profile  
 More options Oct 22 2012, 7:10 pm
From: Guido van Rossum <gu...@python.org>
Date: Mon, 22 Oct 2012 16:09:28 -0700
Local: Mon, Oct 22 2012 7:09 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

I don't know, we've reached territory I don't know at all. Are there
also similar calls for Accept() and Connect() on sockets? Those seem
the other major blocking primitives that are frequently used.

FWIW, here is where I read about IOCP being the only scalable way on
Windows: http://google-opensource.blogspot.com/2010/01/libevent-20x-like-libev...

--
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tom Hoover  
View profile  
 More options Oct 22 2012, 7:37 pm
From: Tom Hoover <thoo...@alum.mit.edu>
Date: Mon, 22 Oct 2012 16:36:35 -0700
Local: Mon, Oct 22 2012 7:36 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)
On Mon, Oct 22, 2012 at 4:09 PM, Guido van Rossum <gu...@python.org> wrote:

It's been years since I've looked at this stuff, but I believe that
you want to use AcceptEx and ConnectEx in conjunction with IOCP.

event_iocp.c and listener.c in libevent 2.0.x could help shed some
light on the details.
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Greg Ewing  
View profile  
 More options Oct 22 2012, 7:49 pm
From: Greg Ewing <greg.ew...@canterbury.ac.nz>
Date: Tue, 23 Oct 2012 12:48:39 +1300
Local: Mon, Oct 22 2012 7:48 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

Guido van Rossum wrote:
> On Mon, Oct 22, 2012 at 3:33 PM, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:

>>It has a broader meaning than the one in Scheme; essentially
>>it's a synonym for "callback".

> (Off-topic:) But does that meaning apply to Scheme? If so, I wish
> someone would have told me 15 years ago...

It does, in the sense that a continuation appears to the
Scheme programmer as a callable object.

The connection goes deeper as well. There's a style of
programming called "continuation-passing style", in which
nothing ever returns -- every function is passed another
function to be called with its result. In a language such
as Scheme that supports tail calls, you can use this style
extensively without fear of overflowing the call stack.

You're using this style whenever you chain callbacks
together using Futures or Deferreds. The callbacks don't
return values; instead, each callback arranges for another
callback to be called, passing it the result.

This is also the way monadic I/O works in Haskell. None
of the I/O functions ever return, they just call another
function and pass it the result. A combination of currying
and syntactic sugar is used to hide the fact that you're
passing callbacks -- aka continuations -- around all
over the place.

Now, it turns out that you can define all the semantics
of Scheme, including its continuations, by writing a Scheme
interpreter in Scheme that doesn't itself use Scheme
continuations. You do it by writing the whole interpereter
in continuation-passing style, and it becomes clear that
at that level, the "continuations" are just ordinary
functions, relying on lexical scoping to capture all of the
necessary state.

> I guess that was just Steve showing off. :-)

Not really -- to someone with a Scheme or FP background,
it's near-impossible to look at something like a chain
of Deferred callbacks without the word "continuation"
springing to mind. I agree that it's not helpful to
anyone without such a background, however.

--
Greg

_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guido van Rossum  
View profile  
 More options Oct 22 2012, 7:55 pm
From: Guido van Rossum <gu...@python.org>
Date: Mon, 22 Oct 2012 16:54:41 -0700
Local: Mon, Oct 22 2012 7:54 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

And, predictably, that gave me a headache... :-)

--Guido van Rossum (sent from Android phone)
On Oct 22, 2012 4:49 PM, "Greg Ewing" <greg.ew...@canterbury.ac.nz> wrote:

_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Greg Ewing  
View profile  
 More options Oct 22 2012, 8:09 pm
From: Greg Ewing <greg.ew...@canterbury.ac.nz>
Date: Tue, 23 Oct 2012 13:07:01 +1300
Local: Mon, Oct 22 2012 8:07 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

Guido van Rossum wrote:
> And, predictably, that gave me a headache... :-)

Oops, sorry, Guido -- I shouldn't have mentioned
the M-word. :-)

--
Greg
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dino Viehland  
View profile  
 More options Oct 23 2012, 12:48 am
From: Dino Viehland <di...@microsoft.com>
Date: Tue, 23 Oct 2012 04:46:43 +0000
Local: Tues, Oct 23 2012 12:46 am
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

I suspect it's because it has the completion routine is being invoked on the same
thread that issued the I/O.  The thread has to first block in an alertable wait (e.g.
WaitForMultipleObjectsEx or WSAWaitForMultipleEvents).  So you'll only get 1
thread doing I/Os and CPU work vs IOCP's where many threads can share both
workloads.

_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Snow  
View profile  
 More options Oct 23 2012, 1:08 am
From: Eric Snow <ericsnowcurren...@gmail.com>
Date: Mon, 22 Oct 2012 23:07:17 -0600
Local: Tues, Oct 23 2012 1:07 am
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

On Mon, Oct 22, 2012 at 9:55 AM, Steve Dower <Steve.Do...@microsoft.com> wrote:
> I think the abstract for PEP 380 sums is up pretty well: "A syntax is proposed for a generator to
> delegate part of its operations to another generator." Using 'yield from' (YF, for convenience)
> requires (a) that the caller is a generator and (b) that the callee is a generator.

Rather, the callee must be some iterable:

  def f():
      yield from [1, 2, 3]

  for x in f():
      print(x)

-eric
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim Jewett  
View profile  
 More options Oct 23 2012, 3:17 am
From: Jim Jewett <jimjjew...@gmail.com>
Date: Tue, 23 Oct 2012 03:17:01 -0400
Local: Tues, Oct 23 2012 3:17 am
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)
On 10/19/12, Guido van Rossum <gu...@python.org> wrote:

> I did a basic timing test using a simple recursive function and a
> recursive PEP-380 coroutine computing the same value (see attachment).
> The coroutine version is a little over twice as slow as the function
> version. I find that acceptable. This went 20 deep, making 2 recursive
> calls at each level (except at the deepest level).

Note that the co-routine code (copied below) does not involve a
scheduler that unwraps futures; there is no scheduler, and nothing
runs concurrently.

    def coroutine(n):
        if n <= 0:
            return 1
        l = yield from coroutine(n-1)
        r = yield from coroutine(n-1)
        return l + 1 + r

I like the above code; my concern was that yield might get co-opted
for use with scheduler loops, which would have to track the parent
task explicitly, and prevent it from being rescheduled too early.

-jJ
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Benoit Chesneau  
View profile  
 More options Oct 23 2012, 3:21 am
From: Benoit Chesneau <beno...@gunicorn.org>
Date: Tue, 23 Oct 2012 09:19:59 +0200
Local: Tues, Oct 23 2012 3:19 am
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

On Oct 22, 2012, at 4:59 PM, Guido van Rossum <gu...@python.org> wrote:

Maybe it is worth to have a look on libuv and the way it mixes threads and  and event loop [1]. Libuv is one of the good event loop around able to use IOCP and other events systems on other arch (kqueue, …) and I was thinking when reading all the exchange around that it would perfectly fit in our cases. Or at least something like it:

- It provides a common api for IO watchers: read, write, writelines, readable, writeable that can probably be extend over remote systems
- Have a job queue system for threds that is working mostly like the Futures but using the event loop

In any case there is a pyuv binding [2] if some want to test. Even a twisted reactor [3]

I myself toying with the idea of porting the Go concurrency model to Python [4] using greenlets and pyuv. Both the scheduler and the way IOs are handled:

- In Go all coroutines are independent from each others and can only communicate via channel. Which has the advantage to allows them to run on different threads when one is blocking. In normal case they are mostly working like grrenlets on a single thread and are simply scheduled in a round-robin way. (mostly like in stackless). On the difference that goroutines can be executed in parallel. When one is blocking another thread will be created to handle other goroutines in the runnable queue.

- For I/Os it exists a common api to all Connections and Listeners (Conn & Listen classes) that generally ask on a poll server. This poll server has for only task to register FDs and wake up the groutines that wait on read or fd events. This this poll server is running in a blocking loop it is automatically let by the scheduler in a thread. This pol server could be likely be replaced by an event loop if someone want.

In my opinion the Go concurrency & memory model [5] could perfectly fit in the Python world and I'm surprised none already spoke about it.

In flower greenlets could probably be replaced by generators but i like the API proposed by any coroutine pattern. I wonder if continulets [6] couldn't be ported in cpython to handle that…

- benoît

[1] http://nikhilm.github.com/uvbook/threads.html & http://github.com/joyent/libuv
[2] https://github.com/saghul/pyuv
[3] https://github.com/saghul/twisted-pyuv
[4] https://github.com/benoitc/flower
[5] http://golang.org/ref/mem
[6] http://doc.pypy.org/en/latest/stackless.html#continulets
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim Jewett  
View profile  
 More options Oct 23 2012, 3:35 am
From: Jim Jewett <jimjjew...@gmail.com>
Date: Tue, 23 Oct 2012 03:34:58 -0400
Local: Tues, Oct 23 2012 3:34 am
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)
On 10/21/12, Guido van Rossum <gu...@python.org> wrote:

> On Sun, Oct 21, 2012 at 1:07 PM, Steve Dower <Steve.Do...@microsoft.com>
> wrote:
>> It has synchronisation which is _aware_ of threads, but it never creates,
>> requires or uses them. It simply ensures thread-safe reentrancy, which
>> will be required for any general solution unless it is completely banned
>> from interacting across CPU threads.
> I don't see it that way. Any time you acquire a lock, you may be
> blocked for a long time. In a typical event loop that's an absolute
> no-no. Typically, to wait for another thread, you give the other
> thread a callback that adds a new event for *this* thread.

That (with or without rescheduling this thread to actually process the
event) is a perfectly reasonable solution, but I'm not sure how
obvious it is.  People willing to deal with the conventions and
contortions of twisted are likely to just use twisted.  A general API
should have a straightforward way to weight for a result; even
explicitly calling wait() may be too much to ask if you want to keep
assuming that other events will cooperate.

 > Perhaps. Lots of possibilities in this design space.

>> (*I'm inclined to define this [the Future interface] as 'result()', 'done()',
>> 'add_done_callback()', 'exception()', 'set_result()' and 'set_exception()'
>> functions. Maybe more, but I think that's sufficient. The current
>> '_waiters' list is an optimisation for add_done_callback(),  and doesn't
>> need to be part of the interface.)
> Agreed. I don't see much use for the cancellation stuff and all the
> extra complexity that adds to the interface.

wait_for_any may well be launching different strategies to solve the
same problem, and intending to ignore all but the fastest.  It makes
sense to go ahead and cancel the slower strategies.  (That said, I
agree that the API shouldn't guarantee that other tasks are actually
cancelled, let alone that they are cancelled before side effects
occur.)

-jJ
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guido van Rossum  
View profile  
 More options Oct 23 2012, 10:45 am
From: Guido van Rossum <gu...@python.org>
Date: Tue, 23 Oct 2012 07:44:31 -0700
Local: Tues, Oct 23 2012 10:44 am
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

Don't worry. There is no way that a scheduler can change the meaning
of yield from. All its power stems from its ability to decide when to
call next(), and that is the same power that the app has itself.

--
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guido van Rossum  
View profile  
 More options Oct 23 2012, 10:49 am
From: Guido van Rossum <gu...@python.org>
Date: Tue, 23 Oct 2012 07:48:36 -0700
Local: Tues, Oct 23 2012 10:48 am
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)
Thanks for the pointer to and description of libuv; it had come up in
my research yet but so far I have not looked it up actively. Now I
will. Also thanks for your reminder of the Goroutine model -- this is
definitely something to look at for inspiration as well. (Though does
Go run on Windows? Or is it part of a secret anti-Microsoft plan? :-)

--Guido

--
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guido van Rossum  
View profile  
 More options Oct 23 2012, 10:55 am
From: Guido van Rossum <gu...@python.org>
Date: Tue, 23 Oct 2012 07:54:46 -0700
Local: Tues, Oct 23 2012 10:54 am
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

I think part of my point is that we can package all this up in a way
that is a lot less scary than Twisted's reputation. And remember,
there are many other frameworks that use similar machinery. There's
Tornado, Monocle (which runs on top of Tornado *or* Twisted), and of
course the stdlib's asyncore, which is antiquated but still much used
-- AFAIL Zope is still built around it.

> A general API
> should have a straightforward way to wait for a result; even
> explicitly calling wait() may be too much to ask if you want to keep
> assuming that other events will cooperate.

Here I have some real world relevant experience: NDB, App Engine's new
Datastore API (which I wrote). It is async under the hood (yield + its
own flavor of Futures), and users who want the most performance from
their app are encouraged to use the async APIs directly -- but users
who don't care can ignore their existence completely. There are
thousands of users, and I've seen people explain the async stuff to
each other on StackOverflow, so I think it is quite accessible.

>> Agreed. I don't see much use for the cancellation stuff and all the
>> extra complexity that adds to the interface.

> wait_for_any may well be launching different strategies to solve the
> same problem, and intending to ignore all but the fastest.  It makes
> sense to go ahead and cancel the slower strategies.  (That said, I
> agree that the API shouldn't guarantee that other tasks are actually
> cancelled, let alone that they are cancelled before side effects
> occur.)

Agreed. And it's not hard to implement a custom cancellation mechanism either.

--
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brett Cannon  
View profile  
 More options Oct 23 2012, 12:14 pm
From: Brett Cannon <br...@python.org>
Date: Tue, 23 Oct 2012 12:09:56 -0400
Local: Tues, Oct 23 2012 12:09 pm
Subject: Re: [Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

Go is available for Windows: http://golang.org/doc/install#windows

On Tue, Oct 23, 2012 at 10:48 AM, Guido van Rossum <gu...@python.org> wrote:

_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 76 - 100 of 112 < Older  Newer >
« Back to Discussions « Newer topic     Older topic »