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: 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: 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> 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" 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" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: 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 r 2012=EB=85=84 7=EC=9B=94 7=EC=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=A4= =ED=9B=84 4=EC=8B=9C 33=EB=B6=84 26=EC=B4=88 UTC+9, Devin Jeanpierre =EB=8B= =98=EC=9D=98 =EB=A7=90: > On Sat, Jul 7, 2012 at 3:09 AM, self.python wr= ote: > > it there somthing that "yield" can't do > > or just it is easier or powerful? >=20 > 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: >=20 > def foo(): > while True: > next_value =3D (yield) > print next_value >=20 > But we can't do this: >=20 > def yap(): > next_value =3D (yield) > print next_value >=20 > def foo(): > while True: > yap() >=20 > 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. >=20 > 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.) >=20 > -- Devin first, thanks for good answer:) but I don't understand why the code def yap():=20 next_value =3D (yield)=20 print next_value=20 def foo():=20 while True:=20 yap()=20 really do. what is the purpose of that code?