Microthreads without Stackless?

Phillip J. Eby pje at telecommunity.com
Mon Sep 27 21:54:32 EDT 2004


"David Pokorny" <davebrok at soda.csua.berkeley.edu> wrote in message news:<naGdnT215sFuTdLcRVn-qQ at lmi.net>...
> "Bryan Olson":
> > Michael Sparks:
> > > [Try Greenlets]
>  
> > Finally, I think I understand the kind of stack-conjuring
> > required to make coroutines work, and it's well outside standard
> > Python's documented extension API.  I've been burned on that
> > kind of thing before.
> 
> Before sending people off to greenlets, I'm starting to understand why you
> have to go check them out via CVS---they are somewhat dangerous in their
> current form. Fortunately, they come with a test that illustrates the
> problem (as long as you compile Python in debug mode, but everyone does
> that, right ;). To get a handle on what is going on here, the following
> "test5" will leak, but calling "test5('noleak')" will not. I haven't the
> foggiest idea why, and gc.collect() cleans up some but not all of the
> excess.
> 
[snip]
> def test5(kind='leak'):
>     def runner(*args, **kwds):
>         x = genlet(g,args,kwds)
>         return x

Have you tried simply 'return genlet(g,args,kwds)'?  My guess is that
this is where the circularity is initially created, because the genlet
points to a greenlet, which has a stack frame that chains back to the
stack frame for the execution of 'runner', whose locals contain 'x',
which refers back to the genlet.



More information about the Python-list mailing list