durusmail: quixote-users: SCGI and session bug.
SCGI and session bug.
quixote - zodb session example, was session bug
2003-07-18
2003-07-17
2003-07-25
SCGI and session bug.
Titus Brown
2003-07-25
-> Seeing as I use postgres for the rest of my application, it is
-> probably most sensible to implement a session manager that stores
-> sessions in a postgresql database. I considered this, pickling the
-> sessions, but first checked to see if I couldn't get away with not
-> doing this work.
->
-> There is of course DirMapping. The only filesystem on my webserver
-> using reiserfs is /tmp, so if I can figure out "secure tempdir
-> creation", maybe I should use DirMapping in /tmp? I also looked at
-> shelve, thought that's the way to go, except that merely doing:
->
-> (WebsitePublisher.__init__)
->         sessionmapping = shelve.open('/var/www-data/quixote-sessions')
->         kwargs['session_mgr'] = SessionManager(WebsiteSession,
->                                                sessionmapping)
->
-> doesn't work - the data never gets flushed to disk. I create at least
-> one session then open the file with shelve in an interactive
-> interpreter, it contains no keys... (I derive from SessionPublisher,
-> since I use scgi, and I can't easily pass parameters to the
-> publisher.)

Try over-riding the publish() function to flush the session mapping; for
example, in Cartwheel, I need to clean up a database handle, and so I do
this:

    def publish(self, stdin, stdout, stderr, env):
        """
        Override the default publish() function to also release the
        object manager at the end of things.
        """
        try:
            SessionPublisher.publish(self, stdin, stdout, stderr, env)
        finally:
            cartwheel.website.release_object_manager()

            # this is where we should save/update the session, no?

(note the prescient last comment; my session handling isn't good at the
moment ;)

cheers,
--titus

reply