questions

1 view
Skip to first unread message

inhahe

unread,
May 20, 2008, 1:52:20 AM5/20/08
to cogen
1. i think that yield statements in python only work in one level of
loop. since cogen uses yield statements, does that mean it won't work
in nested loops?

2. can i use continuations in cogen, for example by pickling tasks?

3. why does the page say that twisted uses continuations? i thought
it uses deferreds, i.e. callbacks.

4. is there a way i could use the iocp support with something outside
of cogen, for example Stackless (in case I need to use Stackless
instead)?

thx..

Ionel Maries Cristian

unread,
May 20, 2008, 3:34:01 AM5/20/08
to co...@googlegroups.com
Hey

On Tue, May 20, 2008 at 8:52 AM, inhahe <inh...@gmail.com> wrote:

1. i think that yield statements in python only work in one level of
loop.  since cogen uses yield statements, does that mean it won't work
in nested loops?
Well, this is a know limitation of python's generators.

However, there is a wrapper that can help you out (cogen.core.events.Call)
http://cogen.googlecode.com/svn/trunk/docs/cogen.core.events.Call.html


2. can i use continuations in cogen, for example by pickling tasks?
I don't think the concept of continuations is synonymous with execution state serialization.
Also, since my implementation is on top of vanilla python you can't have all the
features that stackless offers.
That is you can't pickle tasks. But I wonder why would you need this.

3. why does the page say that twisted uses continuations?  i thought
it uses deferreds, i.e. callbacks.
Twisted uses a form continuation passing style by using deferreds - well, i think i need to edit that page a bit (i forgot to write passing).
http://en.wikipedia.org/wiki/Continuation_passing_style

However, feel free to correct me if i got this wrong.


4. is there a way i could use the iocp support with something outside
of cogen, for example Stackless (in case I need to use Stackless
instead)?
cogen was made for python2.5, but you could interleave cogen's loop in stackless.
I could make you an example if you really need to do this.

Also, cogen doesn't use any stackless features (not even greenlets - wich is
stack hacking spin-off from stackless) so it would be pretty pointless since
you could have a much faster library using those features.

If you really need stackless than you should use stackless.
The are some examples on iocp with stackless here:
http://stacklessexamples.googlecode.com/svn/trunk/
Also, take a look at:
http://code.google.com/p/stacklessexamples/wiki/StacklessNetworking



thx..


What sort of application are you trying to build anyway ?


--
http://ionelmc.wordpress.com

inhahe

unread,
May 20, 2008, 11:25:52 AM5/20/08
to co...@googlegroups.com
On Tue, May 20, 2008 at 3:34 AM, Ionel Maries Cristian <ionel.mc@gmail.com> wrote:
Hey

On Tue, May 20, 2008 at 8:52 AM, inhahe <inh...@gmail.com> wrote:

1. i think that yield statements in python only work in one level of
loop.  since cogen uses yield statements, does that mean it won't work
in nested loops?
Well, this is a know limitation of python's generators.

However, there is a wrapper that can help you out (cogen.core.events.Call)
http://cogen.googlecode.com/svn/trunk/docs/cogen.core.events.Call.html


2. can i use continuations in cogen, for example by pickling tasks?
I don't think the concept of continuations is synonymous with execution state serialization.
Also, since my implementation is on top of vanilla python you can't have all the
features that stackless offers.
That is you can't pickle tasks. But I wonder why would you need this.

im not sure what i need at the moment.  but say i had a web server that calls a particular tasklet based on the session variable. i could do this with a dictionary of continuations, but then i probably could do the same thing with a dict of channels and it'd be easier.  but continuations make it possible to have a working 'back' button for dynamic content, afaik.

i thnk i might have gotten what 'continuations' is wrong.  i gathered that stackless used to support saving the current tasklet state to a variable, which was called continuations, and then for some unknown reason they dropped it, but that you could do the same thing using pickling.
 


3. why does the page say that twisted uses continuations?  i thought
it uses deferreds, i.e. callbacks.
Twisted uses a form continuation passing style by using deferreds - well, i think i need to edit that page a bit (i forgot to write passing).
http://en.wikipedia.org/wiki/Continuation_passing_style

However, feel free to correct me if i got this wrong.

i dont know much about twisted, i was just wondering because if twisted supported continuations i'd just use that.  i don't understand this continuation passing style thing. it reminds me of "futures" and "promises",which i also don't understand :P

 



4. is there a way i could use the iocp support with something outside
of cogen, for example Stackless (in case I need to use Stackless
instead)?
cogen was made for python2.5, but you could interleave cogen's loop in stackless.
I could make you an example if you really need to do this.

Also, cogen doesn't use any stackless features (not even greenlets - wich is
stack hacking spin-off from stackless) so it would be pretty pointless since
you could have a much faster library using those features.

If you really need stackless than you should use stackless.
The are some examples on iocp with stackless here:
http://stacklessexamples.googlecode.com/svn/trunk/
Also, take a look at:
http://code.google.com/p/stacklessexamples/wiki/StacklessNetworking


 


thx..


What sort of application are you trying to build anyway ?

a webserver using microthreads and supporting continuations, er...storing of task states. ideally using iocp.  it was the iocp and the fact that the webserver part had already been written (i assume, since it supports wsgi) that interested me about cogen.   i can't find the iocp support at the links you gave :(

i also found eventlet, but it might not even work on windows.  also i don't think it has iocp.

i think i would like to find out either how to interleave cogen's loop with stackless (to use iocp) or where in those stackless examples it actually uses iocp..

thx for ur help

 


--
http://ionelmc.wordpress.com




Ionel Maries Cristian

unread,
May 20, 2008, 12:18:24 PM5/20/08
to co...@googlegroups.com

There's some iocp stuff here:
http://stacklessexamples.googlecode.com/svn/trunk/examples/fileIO/
http://stacklessexamples.googlecode.com/svn/trunk/libraries/slpmonkeypatch/resources/
I don't know how usefull that is however.

Interleaving should be as simple as instantiating the scheduler and running iter_run in your stackless loop.
I've added a basic example here: http://code.google.com/p/cogen/source/browse/trunk/examples/stackless-integration.py



--
http://ionelmc.wordpress.com
Reply all
Reply to author
Forward
0 new messages