[Stackless] Continuations ?

Arnar Birgisson arnarbi at gmail.com
Mon May 12 19:25:42 CEST 2008


Hey Filip,

On Sun, May 11, 2008 at 2:05 PM, Filip Štědronský <regnarg at seznam.cz> wrote:
>  But now i hit another problem. Considering
>  the way pickle works (and confirmed by experiments), all
>  the locals are (naturally) also pickled. But this can lead
>  to very unpleasant situations with objects that cannot be
>  easily pickled — database links, for example. I am using
>  an ORM and I don't think the wrapper objects would like
>  to be pickled. I wonder wheter there is any way to work
>  that around, or do I have to remove all "dangerous"
>  objects manually from locals before each pickling ?

Have a look at __getstate__ and __setstate__ in the pickle protocol:
http://docs.python.org/lib/pickle-protocol.html

By having your classes supply these methods, you can control exactly
how they are pickled and unpickled. I have successfully for example
pickled database connections. The pickling process just stores enough
information to allow the connection to be reopened, which is precisely
what the unpickling process does. You will not get the _same_ db
connection, but the connection object should look identical for all
practical purposes. You can do this with any object.

cheers,
Arnar

ps. have a look at the wsgi example here, one example shows a seed to
a seaside-like framework that uses tasklets as continuations (alas not
reusable) in a web setting (I'm referring to the "sessionless"
example):
http://code.google.com/p/stacklessexamples/wiki/StacklessWSGI


More information about the Stackless mailing list