[Stackless] Pickling limitations?

Christian Tismer tismer at tismer.com
Fri Sep 19 20:23:02 CEST 2003


Jørgen Hermanrud Fjeld wrote:
> Hi!
> What are the limitations when it comes to pickling uthreads?
> That is, if a uthread calls an external C library, does the whole Python
> interpreter stop until the function returns? (Thus making it impossible to
> execute the pickle until return from C code?)

Yes, the interpreter will stop, and if you save that
thread, it will not be working because it cannot
restore the C stack it needs.
You can of course save and re-run all other uthreads
at any time. Just this one won't work.

> There was also mentioning of pickling Python modules written in C beeing
> possible, but restarting them not working, what practical limitations are
> there to restarting?

Everything that calls from C into Python which then
switches the task creates a tasklet which can't run
after unpickling, if it needs to get back to that
piece of stack. The same holds when the C call
calls PyStackless_Schedule. This is the simple to
use "stack mangling" switching style.
If it poperly uses PyStackless_Schedule_nr and
properly returns to the caller, playing the frame
dribbling game against the toplevel dispatcher, as
it happens with all normal Python functions, then
the tasklet is completely revivable.

Partially revied tasklets can of course run, if they
don't intend to reach the stackful parts of their
frame chain again, i.e. by continuing in the lower
level Python frames and leaving later by an exception
(the latter is only recommended if you know that
your C stack is trivial and does not contain reference
counts -- I didn't check this completely yet, so I can't
really recommend this practice so far).

> And since I wonder about that how do you handle calls to code external to
> the Python compiler in combination with stackless?

Well, this is the brute force thing. I creat a snapshot
of the relevant piece of the C stack and stick it into
a structure. Then I restore a different stack piece
from a diferent tasklet and let that one run.
This is all what Stackless 2.0 does.
The pickling feature only works because the Stackless
1.0 mechanics are back in, which don't produce C stack
state, but put everything into the Python frame.
The tricky part was to support both of these at the same time.

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