[Twisted-web] Re: session, quick one

Donovan Preston dp at ulaluma.com
Fri Apr 23 18:19:58 MDT 2004


On Apr 23, 2004, at 3:31 PM, noema wrote:

> ...I should have said that in the first place: I am trying to set the 
> lifetime of my session but I am not using nevow. Here is the code I 
> use to retrieve the session. It works fine but the session times out 
> every 20min or so:

First of all, for old twisted.web code, just use request.getSession(). 
This does what you appear to have recreated yourself in the code you 
pasted, and what you seem to be asking for in the method name 
request.getCurrentOrNewSession (That's what request.getSession already 
does).

Unfortunately, it doesn't have your proposed lifetime=7200 argument, 
and the lifetime is totally hardcoded into the session. I recommend 
reading twisted.web.server.Request.getSession and 
twisted.web.server.Session; it's not that much code. If you notice, 
Session.checkExpired checks whether to expire the session every 15 
minutes. You might want to create your own code which touches the 
session every 10 minutes or so (by calling touch()) and expires it when 
you like (by calling expire()).

We'll keep this in mind for the upcoming twisted.web cleanup and 
refactoring.

dp




More information about the Twisted-web mailing list