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


Groups > comp.lang.python > #25006

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 <howmuchistoday@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'explicitly': 0.04; 'context': 0.05; 'python': 0.09; 'generators': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'sat,': 0.15; 'code?': 0.16; '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; 'do.': 0.21; 'explicit': 0.22; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'am,': 0.27; 'cc:addr:gmail.com': 0.27; 'first,': 0.27; 'structures': 0.27; '(new': 0.29; 'interactions': 0.29; 'locking': 0.29; 'handled': 0.29; 'function': 0.30; 'code': 0.31; '(and': 0.32; 'switch': 0.32; 'print': 0.32; 'point.': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'thanks': 0.34; 'whatever': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'really': 0.36; 'but': 0.36; 'flow': 0.36; 'does': 0.37; 'level': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'easier': 0.38; '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
Newsgroups comp.lang.python
Date Sat, 7 Jul 2012 01:29:11 -0700 (PDT)
In-Reply-To <mailman.1884.1341646449.4697.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=210.117.199.100; posting-account=MbgxqAoAAACiGFd80Qtwxi2J7qp6KsRy
References <456501fb-af2d-4741-9b73-33c65d7f0aa8@t1g2000pbl.googlegroups.com> <mailman.1884.1341646449.4697.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 210.117.199.100
MIME-Version 1.0
Subject Re: why greenlet, gevent or the stackless are needed?
From "self.python" <howmuchistoday@gmail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org, "self.python" <howmuchistoday@gmail.com>
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>
Message-ID <mailman.1885.1341649754.4697.python-list@python.org> (permalink)
Lines 59
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1341649754 news.xs4all.nl 6948 [2001:888:2000:d::a6]:60101
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25006

Show key headers only | View raw


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?

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