[Twisted-Python] Does the default session expiry work?

markscottwright at gmail.com markscottwright at gmail.com
Tue Mar 2 11:27:11 MST 2010


I'm using twisted 8.2 and (after reading glyph's latest "Twisted in 60  
seconds" entry), I've realized that my sessions never expire. I never added  
any session expiration code, but I thought that the default code expires  
after 15 minutes.

In the below example, I modified twisted\web\server to make  
Session.sessionTimeout be 30 seconds (I also put a print statement in  
Session's ctor, as the log shows), then did two GETs separated by more than  
30 seconds. As the log shows, it looks like the exact same session uid is  
being returned. I would expect it to be deleted by Session.expire, since  
time - lastModifiedTime > 30. Am I missing something?

import sys
from twisted.web import server, static
from twisted.web.resource import Resource
from twisted.web.server import Session, NOT_DONE_YET
from twisted.internet import reactor, ssl
from twisted.python import log

class TestSessionResource(Resource):
isLeaf = True
def render_GET(self, request):
session = request.getSession()
print session.sessionTimeout
print session.uid
print session
return "<html><body><p>Session Test</p></body></html>"

root = TestSessionResource()
reactor.listenTCP(9000, server.Site(root))
log.startLogging(sys.stdout)
reactor.run()

2010-03-02 12:16:49-0600 [-] Log opened.
2010-03-02 12:16:52-0600 [HTTPChannel,0,127.0.0.1] making a new session!!!
2010-03-02 12:16:52-0600 [HTTPChannel,0,127.0.0.1] 30
2010-03-02 12:16:52-0600 [HTTPChannel,0,127.0.0.1]  
338e4aa450f671b2f0115513737e643b
2010-03-02 12:16:52-0600 [HTTPChannel,0,127.0.0.1]  
<twisted.web.server.Session instance at 0x01042AD0>
2010-03-02 12:16:52-0600 [HTTPChannel,0,127.0.0.1] 127.0.0.1 - -  
[02/Mar/2010:18:16:51 +0000] "GET / HTTP/1.1" 200 45 "-" "Mozilla/5.0  
(Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko)  
Chrome/4.0.249.89 Safari/532.5"

2010-03-02 12:16:52-0600 [HTTPChannel,0,127.0.0.1] 30
2010-03-02 12:16:52-0600 [HTTPChannel,0,127.0.0.1]  
338e4aa450f671b2f0115513737e643b
2010-03-02 12:16:52-0600 [HTTPChannel,0,127.0.0.1]  
<twisted.web.server.Session instance at 0x01042AD0>
2010-03-02 12:16:52-0600 [HTTPChannel,0,127.0.0.1] 127.0.0.1 - -  
[02/Mar/2010:18:16:51 +0000] "GET /favicon.ico HTTP/1.1" 200  
45 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5  
(KHTML, like Gecko) Chrome/4.0.249.89 Safari/532.5"
2010-03-02 12:17:45-0600 [HTTPChannel,0,127.0.0.1] 30
2010-03-02 12:17:45-0600 [HTTPChannel,0,127.0.0.1]  
338e4aa450f671b2f0115513737e643b
2010-03-02 12:17:45-0600 [HTTPChannel,0,127.0.0.1]  
<twisted.web.server.Session instance at 0x01042AD0>
2010-03-02 12:17:45-0600 [HTTPChannel,0,127.0.0.1] 127.0.0.1 - -  
[02/Mar/2010:18:17:44 +0000] "GET / HTTP/1.1" 200 45 "-" "Mozilla/5.0  
(Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko)  
Chrome/4.0.249.89 Safari/532.5"

2010-03-02 12:17:45-0600 [HTTPChannel,0,127.0.0.1] 30
2010-03-02 12:17:45-0600 [HTTPChannel,0,127.0.0.1]  
338e4aa450f671b2f0115513737e643b
2010-03-02 12:17:45-0600 [HTTPChannel,0,127.0.0.1]  
<twisted.web.server.Session instance at 0x01042AD0>
2010-03-02 12:17:45-0600 [HTTPChannel,0,127.0.0.1] 127.0.0.1 - -  
[02/Mar/2010:18:17:44 +0000] "GET /favicon.ico HTTP/1.1" 200  
45 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5  
(KHTML, like Gecko) Chrome/4.0.249.89 Safari/532.5"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20100302/66497098/attachment.html>


More information about the Twisted-Python mailing list