[Stackless] Hard switching and pickling
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:
> 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>
> 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
> def aCallable(name):
> print " aCallable<%s>: Before schedule()" % (name,)
> print " aCallable<%s>: After schedule()" % (name,)
> tasks = 
> for name in "ABCDE":
> print "Schedule 1:"
> print "Pickling..."
> pickledTasks = pickle.dumps(tasks)
> print "Schedule 2:"
> unpickledTasks = pickle.loads(pickledTasks)
> for task in unpickledTasks:
> print "Schedule Unpickled Tasks:"
> 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