[Stackless] pickling & killing

Christian Tismer tismer at tismer.com
Sat Sep 27 18:29:44 CEST 2003


Giovanni Bajo wrote:

[CFrame pickling]

> Do you have any planned timeframe for this? For instance, do you plan to do
> this before or after the first release of 3.0?
> Right now, my company needs to understand whether we can rely on tasklet
> pickling or not, this is why I'm asking. If it's going to take weeks, we'll
> have to drop this feature from our product for now.

I'm trying to do it now. But you can live without it, see below.

>>Currently, only simple Python frames can be pickled.
>>You seem to create tasklets bound to no regular Python
>>function, but a method, or a C function.
>>That creates C frames.
> 
> 
> Which means that instead of:
> 
>     tasklet(self.method)()
> 
> I could do:
> 
>     tasklet(lambda: self.method())()

Yes, absolutely!

> right? But this actually causes a new segfault deep inside python22.dll,
> which, alas, I can't reproduce with a small sample. I'll be working on it.

There is a bug right now, that prevends tasklets from correct
unpickling if they never have run. I will fix this bug,
so you can rely on the above to be working.

...

> I'm afraid I still don't understand enough of stackless internals to follow
> you. Can you explain me, from a Python point of view, how can I tell if my
> tasklets have a captured C state or not? And, does it have anything to do
> with the softswitching?

You can task the tasklet, inspect its frame attribute, and follow
this frame chain, looking for a cstack attribute of the frames
that isn't None. This one will be the problem you are seeking for.

def valid_for_revival(t):
     f = t.frame
     while f:
         if f.cstack:
             return False
         f = f.f_back
     return True

...

> I understand. I will try to isolate this but I don't think it's going to be
> easy. Meanwhile, a crash location / call stack within the code might help
> you? If so, I could recompile a debug version of python stackless and make
> it crash.

Yes, please.

...

> Yes, but say I have hundreds of tasklets around, running. The user asks me
> to quit the application. How am I supposed to get hold immediatly of
> references to all the tasklets, and manually call remove & kill for all of
> them before shuttting down my application? Even if I stored the tasklet
> object itself within each "containing" entity, I would still have to
> manually walk through everything in my application and manually kill all the
> tasklets. I can't even rely on destructors because they are not called -
> there are cyclic references (and besides, I tend to avoid destructors since
> they don't play well with GC & cyclic references, and I don't need them most
> of the times).
> 
> So for instance, is there a way to get a list of all the alive tasklets? Or
> all the tasklets insert in the scheduler list? This would be a nice way to
> properly finish all of them immediatly.

while stackless.runcount > 1:
     t = stackless.current.next
     t.kill()

-- 
Christian Tismer             :^)   <mailto:tismer at tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  mobile +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/


_______________________________________________
Stackless mailing list
Stackless at www.tismer.com
http://www.tismer.com/mailman/listinfo/stackless




More information about the Stackless mailing list