A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-September/048682.html below:

[Python-Dev] PEP 334 - Simple Coroutines via SuspendIteration

[Python-Dev] PEP 334 - Simple Coroutines via SuspendIteration [Python-Dev] PEP 334 - Simple Coroutines via SuspendIterationClark C. Evans cce at clarkevans.com
Wed Sep 8 05:29:25 CEST 2004
Josiah Carlson kindly pointed out (off list), that my use of
SuspendIteration violates the standard idiom of exceptions 
terminating the current function. This got past me, beacuse 
I think a generator not as a function, but rather as a shortcut 
to creating iterators.  The offending code is,

|     def NonBlockingResource():
|         yield "one"
|         while True:
|             rand = randint(1,10)
|             if 2 == rand:
|                 break
|             raise SuspendIteration()
|         yield "two"

There are two solutions:
  (a) introduce a new keyword 'suspend'; or,
  (b) don't do that.
  
It is not essential to the proposal that the generator syntax produce
iterators that can SuspendIteration, it is only essential that the
implementation of generators pass-through this exception. Most
non-blocking resources will be low-level components from an async
database or socket library; they can make iterators the old way.

Cheers,

Clark
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4