[Stackless] Hard switching and pickling

OvermindDL1 overminddl1 at gmail.com
Tue Nov 24 05:05:55 CET 2009


Hmm, it appears the stackless list header is broken, it does not reply
to the list, forwarding to the list:

On Mon, Nov 23, 2009 at 1:08 AM, Hervé Coatanhay
<herve.coatanhay at gmail.com> wrote:
> Hi,
>
> After reading this thread
> http://www.stackless.com/pipermail/stackless/2009-September/004271.html, I
> tried to enable hard switching for stackless samples. I encountered the
> following error with "Pickling and unpickling simple tasklets" example:
>
> Traceback (most recent call last):
>   File "/home/hcy/tmp/stackless_test.py", line 32, in <module>
>     schedule()
> RuntimeError: cannot execute invalid frame with 'eval_frame_value': frame
> had a C state that can't be restored.
>
> --
>
> Here the code I used:
>
> from stackless import run, schedule, tasklet, enable_softswitch
> import pickle
>
> enable_softswitch(False)
>
> def aCallable(name):
>     print "  aCallable<%s>: Before schedule()" % (name,)
>     schedule()
>     print "  aCallable<%s>: After schedule()" % (name,)
>
> tasks = []
> for name in "ABCDE":
>     tasks.append(tasklet(aCallable)(name))
>
> print "Schedule 1:"
> schedule()
>
> print
> print "Pickling..."
> pickledTasks = pickle.dumps(tasks)
>
> print
> print "Schedule 2:"
> schedule()
>
> unpickledTasks = pickle.loads(pickledTasks)
> for task in unpickledTasks:
>     task.insert()
> print
> print "Schedule Unpickled Tasks:"
> schedule()
>
> --
>
> Is there a design incompatibility between "hard switching" and pickle ?

"Hard switching" switches the stack pointers on the processor, it
supports things like having a C function on the call stack, as such,
hard switching is inherently not picklable.  "Soft switching" just
switches the Python frames, which is a lot faster, does not supports
any C functions on the call stack, and can pickled.




More information about the Stackless mailing list