Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25003 > unrolled thread
| Started by | "self.python" <howmuchistoday@gmail.com> |
|---|---|
| First post | 2012-07-07 00:09 -0700 |
| Last post | 2012-07-07 17:38 +0200 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.python
why greenlet, gevent or the stackless are needed? "self.python" <howmuchistoday@gmail.com> - 2012-07-07 00:09 -0700
Re: why greenlet, gevent or the stackless are needed? Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-07-07 03:33 -0400
Re: why greenlet, gevent or the stackless are needed? "self.python" <howmuchistoday@gmail.com> - 2012-07-07 01:29 -0700
Re: why greenlet, gevent or the stackless are needed? "self.python" <howmuchistoday@gmail.com> - 2012-07-07 01:29 -0700
Re: why greenlet, gevent or the stackless are needed? Damjan <gdamjan@gmail.com> - 2012-07-07 17:38 +0200
| From | "self.python" <howmuchistoday@gmail.com> |
|---|---|
| Date | 2012-07-07 00:09 -0700 |
| Subject | why greenlet, gevent or the stackless are needed? |
| Message-ID | <456501fb-af2d-4741-9b73-33c65d7f0aa8@t1g2000pbl.googlegroups.com> |
(I'm very new to this coroutine part so It's not supposed to attack these modules, just I don't know the differences) atfer version 2.5, python officially support coroutine with yield. and then, why greenlet, gevent, Stackless python are still useful? it there somthing that "yield" can't do or just it is easier or powerful?
[toc] | [next] | [standalone]
| From | Devin Jeanpierre <jeanpierreda@gmail.com> |
|---|---|
| Date | 2012-07-07 03:33 -0400 |
| Message-ID | <mailman.1884.1341646449.4697.python-list@python.org> |
| In reply to | #25003 |
On Sat, Jul 7, 2012 at 3:09 AM, self.python <howmuchistoday@gmail.com> wrote:
> it there somthing that "yield" can't do
> or just it is easier or powerful?
couroutine-like generators can't give up control flow unless they are
the top level function handled by the coroutine controller thing. For
example, we can do this:
def foo():
while True:
next_value = (yield)
print next_value
But we can't do this:
def yap():
next_value = (yield)
print next_value
def foo():
while True:
yap()
If we explicitly say that "yap" can control us, via "yield from" (new
in Python 3.3), then we can do something like the above, but this
still requires explicit markup. In all other releases of Python, this
is impossible.
On the other hand, coroutines in greenlet et al can do a coroutine
context switch at any point. The upside is that this is more flexible
(and does something generators pre-3.3 cannot). The downside is that
you now need locking structures to guarantee atomic interactions with
a shared resource, whereas with generators you know that you always
are the sole thing running, until you do a yield (and unless real
threads or greenlet or whatever are involved, of course.)
-- Devin
[toc] | [prev] | [next] | [standalone]
| From | "self.python" <howmuchistoday@gmail.com> |
|---|---|
| Date | 2012-07-07 01:29 -0700 |
| Message-ID | <mailman.1885.1341649754.4697.python-list@python.org> |
| In reply to | #25005 |
r
2012년 7월 7일 토요일 오후 4시 33분 26초 UTC+9, Devin Jeanpierre 님의 말:
> On Sat, Jul 7, 2012 at 3:09 AM, self.python <howmuchistoday@gmail.com> wrote:
> > it there somthing that "yield" can't do
> > or just it is easier or powerful?
>
> couroutine-like generators can't give up control flow unless they are
> the top level function handled by the coroutine controller thing. For
> example, we can do this:
>
> def foo():
> while True:
> next_value = (yield)
> print next_value
>
> But we can't do this:
>
> def yap():
> next_value = (yield)
> print next_value
>
> def foo():
> while True:
> yap()
>
> If we explicitly say that "yap" can control us, via "yield from" (new
> in Python 3.3), then we can do something like the above, but this
> still requires explicit markup. In all other releases of Python, this
> is impossible.
>
> On the other hand, coroutines in greenlet et al can do a coroutine
> context switch at any point. The upside is that this is more flexible
> (and does something generators pre-3.3 cannot). The downside is that
> you now need locking structures to guarantee atomic interactions with
> a shared resource, whereas with generators you know that you always
> are the sole thing running, until you do a yield (and unless real
> threads or greenlet or whatever are involved, of course.)
>
> -- Devin
first, thanks for good answer:)
but I don't understand why the code
def yap():
next_value = (yield)
print next_value
def foo():
while True:
yap()
really do.
what is the purpose of that code?
[toc] | [prev] | [next] | [standalone]
| From | "self.python" <howmuchistoday@gmail.com> |
|---|---|
| Date | 2012-07-07 01:29 -0700 |
| Message-ID | <d1fd65ef-2e0d-4577-b768-f55b6fcc4bbe@googlegroups.com> |
| In reply to | #25005 |
r
2012년 7월 7일 토요일 오후 4시 33분 26초 UTC+9, Devin Jeanpierre 님의 말:
> On Sat, Jul 7, 2012 at 3:09 AM, self.python <howmuchistoday@gmail.com> wrote:
> > it there somthing that "yield" can't do
> > or just it is easier or powerful?
>
> couroutine-like generators can't give up control flow unless they are
> the top level function handled by the coroutine controller thing. For
> example, we can do this:
>
> def foo():
> while True:
> next_value = (yield)
> print next_value
>
> But we can't do this:
>
> def yap():
> next_value = (yield)
> print next_value
>
> def foo():
> while True:
> yap()
>
> If we explicitly say that "yap" can control us, via "yield from" (new
> in Python 3.3), then we can do something like the above, but this
> still requires explicit markup. In all other releases of Python, this
> is impossible.
>
> On the other hand, coroutines in greenlet et al can do a coroutine
> context switch at any point. The upside is that this is more flexible
> (and does something generators pre-3.3 cannot). The downside is that
> you now need locking structures to guarantee atomic interactions with
> a shared resource, whereas with generators you know that you always
> are the sole thing running, until you do a yield (and unless real
> threads or greenlet or whatever are involved, of course.)
>
> -- Devin
first, thanks for good answer:)
but I don't understand why the code
def yap():
next_value = (yield)
print next_value
def foo():
while True:
yap()
really do.
what is the purpose of that code?
[toc] | [prev] | [next] | [standalone]
| From | Damjan <gdamjan@gmail.com> |
|---|---|
| Date | 2012-07-07 17:38 +0200 |
| Message-ID | <mailman.1893.1341675491.4697.python-list@python.org> |
| In reply to | #25003 |
On 07.07.2012 09:09, self.python wrote: > (I'm very new to this coroutine part > so It's not supposed to attack these modules, > just I don't know the differences) > > atfer version 2.5, python officially support coroutine with yield. > and then, why greenlet, gevent, Stackless python are still useful? > > it there somthing that "yield" can't do > or just it is easier or powerful? The greenlet site has some very simple examples what it can provide. For example jumping from one function in another, and back http://greenlet.readthedocs.org/en/latest/index.html Gevent then uses greenlet to do lightweight "processes" (greenlets) that are I/O scheduled. This allows for a simple model of programming that scales to a large number of concurrent connections. You could do that with threads but you can't start as many threads as greenlets, since they have a much larger memory address space footprint. There's one function, called the gevent hub, that waits for any I/O event and then switches to the function that "blocked" on that I/O. -- damjan
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web