[Stackless] cPickle should work?

Richard richard at ccpgames.com
Thu May 4 08:51:39 CEST 2006


> From: Andrew Francis on 02 May 2006 18:31
> When I run the following programme with dump(), it
> crashes with an RuntimeError exception at the end of
> the problem. When I use dumps(), things are fine. I am
> using Stackless binary 2.4.3 Dlls. I have included the
> programme.
>         
> .......
>         
> p = P("A", [Task("C",c[1]),Task("B",c[2])], c[0])

The problem is the order in which the tasklets and their
channels are unpickled and restored with their old state.
Where restored is taken to mean setstate called on them.

The two Task instances unpickle fine, with the tasklet
restored and then the channel they hold a reference to
restored.  But then the channel for p is restored, and
then the tasklet p itself is restored.

Why this is a problem, is because tasklet restoration
cleared the blocking flag, the flag that the channel
sets on the tasklets within it.  So what we have left is
a tasklet which is linked into the channel's chain of
tasklets (the channel was restored with the tasklet
passed to it, and it added the tasklet to itself), and
has an invalid blocking flag, because when the tasklet
restored itself, it assumed it was not linked to a 
channel yet, and cleared the flag leaving it for a
channel to do later.

When the tasklet is garbage collected, it is scheduled
with a TaskletExit exception, but, because it is linked
to the channel and not blocked, the scheduling logic
does not link it in to the scheduler's chain of
scheduled tasklets.  Instead it is left linked brokenly
to the channel.  And when the tasklet has had the
TaskletExit exception passed into it and has run, the
scheduler goes to remove it as the current tasklet and
crashes with an access violation on the incorrect
scheduled tasklet chain (which only contains the main
tasklet in this case).

There are two possible solutions to this that I can see:

 1. Change setstate in the tasklet to not clear the
    blocking flag if it is linked to other tasklets
    already.

I do not know what side-effects this might have. Perhaps
it is possible for something to happen between when
setstate is called on the channel and when it is called
on the tasklet.

Anyone have any experience with this?

 2. Look into correcting the pickling/unpickling order
    so that tasklets are always restored before channels
    they are on.

I think this is a lost cause.  Additional Stackless
specific changes to the code base sound like a nuisance
and I don't think that is is reasonable to try and guarantee
the restoration order.

Cheers,
Richard.

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



More information about the Stackless mailing list