[Stackless] pickling & killing

Christian Tismer tismer at tismer.com
Thu Sep 11 18:00:53 CEST 2003


Giovanni Bajo wrote:

> Hello,
>  
> First of all, my overall experience with Stackless 3.0 is _AWESOME_ till 
> now, many thanks Christian.

:-))

> I have a few problems which I can't solve by myself:
>  
> - Task pickling. Whenever I try to pickle one of my tasklets I get a 
> "TypeError: can't pickle cframe objects". What is a cframe object? How 
> am I supposed to make pickling work?

Right, this is an omission my now. CFrames don't support
pickling at the moment, but they will (easy to do).
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.
Or, it may be that you are creating your tasklets from
C, without a running frame on the stack. I think, this
also needs to create a C frame.

> - While looking into the docstrings/sources, I noticed that you say that 
> you can't always reload a pickled task, and you won't know if it's 
> possible until you try it. Would you please elaborate on this? Which 
> conditions make impossible for a tasklet to be unpickled? How can I make 
> sure I will never hit those conditions? Why is it not possibile to test 
> those conditions at pickling time instead of unpicling?

Despite small omissions like the CFrame thing, pickling is
always possible, also unpickling, but some frames might not run.
This is true for all frames which have a captured C state,
that is, the frame was switched by changing the C stack,
and that exactly is what I can pickle, but it makes no sense
to unpickle.
It is possible to test this at pickling time, but it
would prevend useful cases. You might ant to pickle
a thread, just for later inspection by some program,
whether it can be restarted or not.
You might also have this scenario:

    Frame A with C stack   (can't be re-run after unpicling)
    Frame B
    Frame C

After unpickling, you can continue in Frame C.
If your code finally gets back to Frame A, you will
get an exception, since this frame cannot be run.
But it might of course be true that you don't intend
to run it, but leave it by an exception or another
jump, anyway.

> - Task killing. What is the proper sequence to kill a tasklet? I first 
> call the remove method to unschedule it, and that works. Then if I try 
> either .kill() or even del the variable, I get a segfault within 
> python.dll (which I did not trace, yet). Any idea what it's going on?

Calling the kill() method *should* be the way to do it.
If it doesn't, then I need more information and demo
code to find out, why. This part of the system is very
new.

> - The docstring of remove() says that a tasklet with a "C frame 
> attacched" should be either continued or killed after a remove(). What 
> does it mean "a C frame attacched"? Would you please elaborate on this?

The state of the frame is not stored in Pyhton variables,
but there is a snapshot of the C stack. This works for
normal scheduling purposes, but makes no sense after
unpickling, since the C stack is most probably invalid.

> - Garbage collection. I notice that the garbage collector gets stuck 
> when it finds tasklets around (for instance, as attributes of other 
> objects). It seems like that tasklets do not cooperate very well with 
> the garbage collector. Right now, I must manually go through my objects 
> and del the tasklets before being able to gc.collect().

You sem not to finish your tasklets properly.
If a tasklet is done with its task, it has no
longer a frame attached and cannot produce
cycles, but is a primitive object. Therefore,
I didn't pay much attention to the GC.

> Any idea what it 
> might be going on? I noticed in taskletobject.c that there is no flag 
> Py_TPFLAGS_HAVE_GC in the tasklet type. I tried to put it in (and I 
> changed the tp_free pointer to _PyObject_GC_Del) but I only got some 
> exception / segault here and there during garbage collection, and 
> nothing else.

I have to look into this, further.
Needing garbage collection to get rid of a tasklet
indicates improper use of tasklets. (or maybe yet
another bug on my side :-)
Tasklets should be finished before collected.

ciao - chris

-- 
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  pager +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