[Stackless] Continuations ?
alain.poirier at net-ng.com
Tue May 13 18:40:58 CEST 2008
On Monday 12 May 2008 19:25:42 Arnar Birgisson wrote:
> 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:
> 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.
> 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"
We are also using tasklets pickling/unpickling in our framework to have the
same components model than Seaside, "back" and "fork" included.
Regarding the pickling of the ORM entities, we choose to let the developers
do the separation between the logic objects which are pickling and the
data objects (the ORM entities) that are recreated on each requests.
We found this politic simpler, more explicit and saner. There is indeed
conceptual / consistency problems if the data are keeps both in the
continuations and in the database.
More information about the Stackless