Update of /cvsroot/webware/Webware/WebKit
In directory usw-pr-cvs1:/tmp/cvs-serv24655
Modified Files:
SessionFileStore.py
Log Message:
Switching from using a temporary file for SessionFileStore to using a thread-lock. It's safer and probably faster.
Index: SessionFileStore.py
===================================================================
RCS file: /cvsroot/webware/Webware/WebKit/SessionFileStore.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** SessionFileStore.py 2001/11/12 12:48:49 1.9
--- SessionFileStore.py 2001/11/16 17:24:35 1.10
***************
*** 2,5 ****
--- 2,6 ----
import os
from glob import glob
+ import threading
debug = 0
***************
*** 28,31 ****
--- 29,33 ----
SessionStore.__init__(self, app)
self._sessionDir = app.serverSidePath('Sessions')
+ self._lock = threading.Lock()
***************
*** 41,66 ****
print '>> get (%s)' % key
filename = self.filenameForKey(key)
try:
! file = open(filename)
! except IOError:
! raise KeyError, key
! item = self.decoder()(file)
! file.close()
return item
def __setitem__(self, key, item):
- # @@ 2001-11-12 ce: It's still possible that two threads are updating the same
- # session as the same time (due to the user having two windows open) in which
- # case one will clobber the results of the other! Probably need file locking
- # to solve this.
-
if debug:
print '>> setitem(%s,%s)' % (key, item)
filename = self.filenameForKey(key)
! tmpName = os.tempnam(os.path.dirname(filename), 'tmp')
! file = open(tmpName, 'w')
! self.encoder()(item, file)
! file.close()
! os.rename(tmpName, filename)
def __delitem__(self, key):
--- 43,69 ----
print '>> get (%s)' % key
filename = self.filenameForKey(key)
+ self._lock.acquire()
try:
! try:
! file = open(filename)
! except IOError:
! raise KeyError, key
! item = self.decoder()(file)
! file.close()
! finally:
! self._lock.release()
return item
def __setitem__(self, key, item):
if debug:
print '>> setitem(%s,%s)' % (key, item)
filename = self.filenameForKey(key)
! self._lock.acquire()
! try:
! file = open(filename, 'w')
! self.encoder()(item, file)
! file.close()
! finally:
! self._lock.release()
def __delitem__(self, key):
|