Garrett G. Hodgson wrote:
But generally I suspect your problem is that you have something in the
session object which can't be pickled like an open file or database
connection.
    

i bet that's it.  there's a db connection stored in the session().
what's the right way to maintain a persistent connection, vs. having to connect
each time?

thanks very much for your help.

  
What I am doing is to keep in the Session() object, enough information to re-create connections.  Then I have a seperate dictionary that only lives in memory which is keyed on the session object to reference data which can't be serialized.

I extend my Session object to support this behavior, providing an npget() method which retrieves non-persistent session data.   npget() also supports an init parameter which allows specifying a function to construct the value (ie: open the database) if the key is not already present.  This helps readability and allows code like:

    db = session.npget( "DB", init=lambda id=session.userid : opendatabase( id ) )

If the database connection does not exist, it executes the init code to open the database with the session.userid as the argument.

Should we consider adding something like this to the standard session objects?   It might help since we occasionally get people running into errors as a result of sticking the database connection on the session object directly.

-Stuart-