Changeset 1367
- Timestamp:
- 09/15/06 15:22:17
- Files:
-
- trunk/cherrypy/lib/sessions.py (modified) (5 diffs)
- trunk/cherrypy/test/test_conn.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/lib/sessions.py
r1302 r1367 87 87 def save(self): 88 88 """Save session data.""" 89 # If session data has never been loaded then it's never been 90 # accessed: no need to delete it 91 if self.loaded: 92 t = datetime.timedelta(seconds = self.timeout * 60) 93 expiration_time = datetime.datetime.now() + t 94 self._save(expiration_time) 95 96 if self.locked: 97 # Always release the lock if the user didn't release it 98 self.release_lock() 89 try: 90 # If session data has never been loaded then it's never been 91 # accessed: no need to delete it 92 if self.loaded: 93 t = datetime.timedelta(seconds = self.timeout * 60) 94 expiration_time = datetime.datetime.now() + t 95 self._save(expiration_time) 96 97 finally: 98 if self.locked: 99 # Always release the lock if the user didn't release it 100 self.release_lock() 99 101 100 102 def load(self): … … 186 188 except KeyError: 187 189 pass 190 try: 191 del self.locks[id] 192 except KeyError: 193 pass 188 194 189 195 def _load(self): … … 198 204 def acquire_lock(self): 199 205 self.locked = True 200 self.locks.setdefault(self.id, threading. Semaphore()).acquire()206 self.locks.setdefault(self.id, threading.RLock()).acquire() 201 207 202 208 def release_lock(self): … … 366 372 # If the session is still locked we release the lock 367 373 sess.release_lock() 374 del cherrypy._serving.session 368 375 close.failsafe = True 376 close.priority = 90 369 377 370 378 … … 389 397 cherrypy.session = cherrypy._ThreadLocalProxy('session', _def_session) 390 398 391 # Create and attach a new Session instance to cherrypy. request.399 # Create and attach a new Session instance to cherrypy._serving. 392 400 # It will possess a reference to (and lock, and lazily load) 393 401 # the requested session data. trunk/cherrypy/test/test_conn.py
r1345 r1367 211 211 212 212 # Put request 1 213 conn.putrequest("GET", "/", skip_host=True) 214 conn.putheader("Host", self.HOST) 215 conn.endheaders() 216 217 # Put request 2 218 conn._output('GET /hello HTTP/1.1') 219 conn._output("Host: %s" % self.HOST) 220 conn._send_output() 221 222 # Retrieve response 1 223 response = conn.response_class(conn.sock, method="GET") 224 response.begin() 225 body = response.read() 226 self.assertEqual(response.status, 200) 227 self.assertEqual(body, pov) 228 229 # Retrieve response 2 213 conn.putrequest("GET", "/hello", skip_host=True) 214 conn.putheader("Host", self.HOST) 215 conn.endheaders() 216 217 for trial in xrange(5): 218 # Put next request 219 conn._output('GET /hello HTTP/1.1') 220 conn._output("Host: %s" % self.HOST) 221 conn._send_output() 222 223 # Retrieve previous response 224 response = conn.response_class(conn.sock, method="GET") 225 response.begin() 226 body = response.read() 227 self.assertEqual(response.status, 200) 228 self.assertEqual(body, "Hello, world!") 229 230 # Retrieve final response 230 231 response = conn.response_class(conn.sock, method="GET") 231 232 response.begin()

