Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25005

Re: why greenlet, gevent or the stackless are needed?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <jeanpierreda@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'explicitly': 0.04; 'context': 0.05; 'python': 0.09; 'generators': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'sat,': 0.15; 'coroutines': 0.16; 'downside': 0.16; 'foo():': 0.16; 'markup.': 0.16; 'resource,': 0.16; 'threads': 0.16; 'true:': 0.16; 'wrote:': 0.17; 'yield': 0.17; 'explicit': 0.22; 'received:mail- bk0-f46.google.com': 0.22; 'cc:2**0': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'am,': 0.27; 'received:209.85.214.46': 0.27; 'structures': 0.27; 'message-id:@mail.gmail.com': 0.27; '(new': 0.29; 'interactions': 0.29; 'locking': 0.29; 'handled': 0.29; 'function': 0.30; '(and': 0.32; 'switch': 0.32; 'print': 0.32; 'point.': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'whatever': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'flow': 0.36; 'does': 0.37; 'level': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'real': 0.61; 'subject:, ': 0.61; 'more': 0.63; 'jul': 0.65; 'us,': 0.74; 'sole': 0.75; 'running,': 0.84; 'upside': 0.84; 'controller': 0.91; 'hand,': 0.97
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=4iwYp23CEVhToKMDVNhOD25/jNi0pPTiHIwp6UC+yw4=; b=HDdNFiobvq1i2qGEL3h7Cou1L8iySKTZ19KR4BShfA6Vbr+E1TgyThMPy42fHei3fU 42wm5HrTCgYTtMoA99Uig6KmGaJkyR3Bj/+sBL0cIo90OOiLe/gOV5nVJJ35Q4mApcMy hqdYb49aAggF2lMYoWDGP5q8WXJ+7rhI1/12MYWcoHa1PixdgP3iHBcTMJdgNYiqTxk2 Al7rFiWw2i+tjLcqdC/CCZoz+ZECZYel8SbHMPbgggRgLfKOvFUs6itMFOiBMQWwi2lN wP0+LgwkeKbppUM+aQjIYJantwnhh1CM+zYf1NKu4R7OmS9uehSJsekISD5JT5QQNL9E NjSw==
MIME-Version 1.0
In-Reply-To <456501fb-af2d-4741-9b73-33c65d7f0aa8@t1g2000pbl.googlegroups.com>
References <456501fb-af2d-4741-9b73-33c65d7f0aa8@t1g2000pbl.googlegroups.com>
From Devin Jeanpierre <jeanpierreda@gmail.com>
Date Sat, 7 Jul 2012 03:33:26 -0400
Subject Re: why greenlet, gevent or the stackless are needed?
To "self.python" <howmuchistoday@gmail.com>
Content-Type text/plain; charset=UTF-8
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1884.1341646449.4697.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1341646449 news.xs4all.nl 6937 [2001:888:2000:d::a6]:54847
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25005

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web