473,654 Members | 3,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Python generators (coroutines)

On Wed, 23 Apr 2008 07:17:46 -0700 (PDT), ro*********@gma il.com wrote:
>I would really like to know more about python 2.5's new generator
characteristic s that make them more powerful and analogous to
coroutines. Is it possible for instance to employ them in situations
where I would normally use a thread with a blocking I/O (or socket)
operation? If it is, could someone show me how it can be done? There
appears to be a very limited amount of documentation in this repect,
unfortunatel y.
They're not coroutines. The difference between generators in Python 2.4
and in Python 2.5 is that in Python 2.5, `yield´ can be used as part of
an expression. If a generator is resumed via its `send´ method, then the
`yield´ expression evaluates to the value passed to `send´.

You still can't suspend execution through arbitrary stack frames; `yield´
only suspends the generator it is in, returning control to the frame
immediately above it on the stack.

You can build a trampoline based on generators, but you can do that in
Python 2.4 just as easily as you can do it in Python 2.5.

Jean-Paul
Jun 27 '08 #1
0 1187

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4341
by: Doug | last post by:
I am thinking of using a Python based HTTP server instead of Apache. I would be interested in one that employed generators and coroutines. I know those are fairly new features of python, so maybe nothing is available yet. Doug
28
4844
by: Matt Leslie | last post by:
Hi, I'm trying to use microthreads under stackless python, since they sound like exactly what I am after, but I am having very little success. I've got a fresh install of python 2.3.3 from python.org, then downloaded the binary python2.3 release of stackless python from www.stackless.com. This contained three files: python23.dll, python23.lib, python23.exp
5
3232
by: Robert Oschler | last post by:
Preamble: - I know this is the Python forum - I know about (and have used) Jython I already posted this question in comp.lang.java. But after a week I have still not received a single reply. One of my favorite Python features is generators. I have to use Java for one particular project (it happens). I would like to have something at
7
1193
by: Ben Sizer | last post by:
A simple question - can anybody give a short example of how these work and what they are good for? I've read PEP 342 and the associated bit in the What's New section and it's still all Greek to me. The latter seems to focus on how to do it, rather than why you'd do it, so it doesn't aid the understanding too much. -- Ben Sizer
852
28320
by: Mark Tarver | last post by:
How do you compare Python to Lisp? What specific advantages do you think that one has over the other? Note I'm not a Python person and I have no axes to grind here. This is just a question for my general education. Mark
3
1477
by: rocco.rossi | last post by:
I would really like to know more about python 2.5's new generator characteristics that make them more powerful and analogous to coroutines. Is it possible for instance to employ them in situations where I would normally use a thread with a blocking I/O (or socket) operation? If it is, could someone show me how it can be done? There appears to be a very limited amount of documentation in this repect, unfortunately. Thank you.
1
164
by: Jean-Paul Calderone | last post by:
On Wed, 23 Apr 2008 10:53:03 -0700 (PDT), Michele Simionato <michele.simionato@gmail.comwrote: You could have #2. It's a trivial variation of sending a value. For example, http://twistedmatrix.com/trac/browser/trunk/twisted/internet/defer.py#L555 Jean-Paul
12
1256
by: castironpi | last post by:
I want to talk to the newsgroup. As I have found that its readers will be non-trivially attentive, I esteem it a worthwhile production, for finely divided values of worth & while. (Disclaimer: Don't call me millionaire; life & money...). It is not clear that I will be posting code first thing, for a range of values of I. (Yes I have tackled decentralization and contribution in identity before.) It's possible that I just like to...
0
8376
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8489
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8594
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7307
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.