Eduardo Elgueta wrote:
> Geoff,
> 
> Thanks for your answer.
> 
> I usually store a database connection in my sessions. How can I make
> the database connection pickable? Are regular classes pickable or I
> have to add custom code? Sessions expire because of this or they're
> just not saved to disk?
> 
> Thanks again.
> 
> Ed.

I would recommend reading the Python documentation on pickling here:
http://www.python.org/doc/current/lib/pickle-inst.html

But briefly, database connections are definitely not going to be picklable
by themselves.  Class instances are picklable, by default pickling all of
the attributes of the class.  But you can add special __getstate__ and
__setstate__ methods to a class to control exactly what part of the
instance's state is pickled and unpickled.  So you could wrap your database
connection in a class, and have only the connection _information_ be
pickled, not the connection itself; and reconstruct the connection from that
information on unpickling.

I hope that leads you in the right direction...

I'm not really sure what happens if the session can't be pickled to disk,
but it certainly causes big problems if you try to restart your app server
so you really ought to avoid it.

- Geoff


-------------------------------------------------------
This SF.net email is sponsored by OSDN's Audience Survey.
Help shape OSDN's sites and tell us what you think. Take this
five minute survey and you could win a $250 Gift Certificate.
http://www.wrgsurveys.com/2003/osdntech03.php?site=8
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to