[Zope] Session manager without pickle?

Dieter Maurer dieter@handshake.de
Sun, 28 Apr 2002 00:26:37 +0200


Dietmar Schwertberger writes:
 > I'd like to open and store a database connection per session to enable
 > things like transactions over multiple http accesses, use of (existing)
 > python code, user authorization via database server etc.
 > Unfortunately the session manager tries to pickle the connection object,
 > which of course doesn't work here.
 > Is it possible to avoid this?
I fear not. At least it will not be easy.
 > Anyway, as session data should be stored in RAM, I don't see the point of
 > pickling...
You must be very careful!

  As I found out (the hard way), it is very dangerous to store
  persistent objects in RAM:

    A persistent object has a reference to the ZODB connection.
    This reference is only valid in the current request.
    A new request may get a different ZODB connection, making
    the one in the persistent object invalid.
    Non-deterministic failures of the form: "Unable to load ..."
    "XXX does not have attribute YYY" may result.

  Acquisition wrappers which are themselvse not persistent
  contain references to persistent objects. Therefore,
  they, too, are dangerous to store in RAM.

 > If it's possible to do what I want, is it also possible/necessary to avoid
 > multiple concurrent accesses from the same user/session?
That depends on what you are doing and the multi-thread safety
of your data structure.

You may look at "SharedResource" to find out how to synchronize
when necessary. See

  <http://www.dieter.handshake.de/pyprojects/zope>



Dieter