Django

Code

Changeset 8707

Show
Ignore:
Timestamp:
08/29/08 12:32:21 (3 months ago)
Author:
mtredinnick
Message:

Reverted #8688 for now, since it merely introduced different bugs, rather than
fixing the problem. We have a plan B (and plan C, if needed), so this will be
fixed in a different way.

Refs #8616.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r8688 r8707  
    364364    sloonz <simon.lipp@insa-lyon.fr> 
    365365    SmileyChris <smileychris@gmail.com> 
    366     Warren Smith <warren@wandrsmith.net> 
    367366    smurf@smurf.noris.de 
    368367    Vsevolod Solovyov 
  • django/trunk/django/contrib/sessions/backends/file.py

    r8688 r8707  
    66from django.contrib.sessions.backends.base import SessionBase, CreateError 
    77from django.core.exceptions import SuspiciousOperation, ImproperlyConfigured 
    8 from django.core.files import locks 
    98 
    10 IO_LOCK_SUFFIX = "_iolock" 
    119 
    1210class SessionStore(SessionBase): 
     
    4543        return os.path.join(self.storage_path, self.file_prefix + session_key) 
    4644 
    47     def _key_to_io_lock_file(self, session_key=None): 
    48         """ 
    49         Get the I/O lock file associated with this session key. 
    50         """ 
    51         return self._key_to_file(session_key) + IO_LOCK_SUFFIX 
    52  
    5345    def load(self): 
    5446        session_data = {} 
    5547        try: 
    56             # Open and acquire a shared lock on the I/O lock file before 
    57             # attempting to read the session file.  This makes us wait to read 
    58             # the session file until another thread or process is finished 
    59             # writing it. 
    60             lock_path = self._key_to_io_lock_file() 
    61             io_lock_file = open(lock_path, "rb") 
    62             locks.lock(io_lock_file, locks.LOCK_SH) 
     48            session_file = open(self._key_to_file(), "rb") 
    6349            try: 
    64                 session_file = open(self._key_to_file(), "rb") 
    6550                try: 
    66                     try: 
    67                         session_data = self.decode(session_file.read()) 
    68                     except (EOFError, SuspiciousOperation): 
    69                         self.create() 
    70                 finally: 
    71                     session_file.close() 
     51                    session_data = self.decode(session_file.read()) 
     52                except (EOFError, SuspiciousOperation): 
     53                    self.create() 
    7254            finally: 
    73                 locks.unlock(io_lock_file) 
    74                 io_lock_file.close() 
    75                 os.unlink(lock_path) 
     55                session_file.close() 
    7656        except IOError: 
    7757            pass 
     
    9777        session_data = self._get_session(no_load=must_create) 
    9878        try: 
    99             # Open and acquire an exclusive lock on the I/O lock file before 
    100             # attempting to write the session file.  This makes other threads 
    101             # or processes wait to read or write the session file until we are 
    102             # finished writing it. 
    103             lock_path = self._key_to_io_lock_file() 
    104             io_lock_file = open(lock_path, "wb") 
    105             locks.lock(io_lock_file, locks.LOCK_EX) 
     79            fd = os.open(self._key_to_file(self.session_key), flags) 
    10680            try: 
    107                 fd = os.open(self._key_to_file(self.session_key), flags) 
    108                 try: 
    109                     os.write(fd, self.encode(session_data)) 
    110                 finally: 
    111                     os.close(fd) 
     81                os.write(fd, self.encode(session_data)) 
    11282            finally: 
    113                 locks.unlock(io_lock_file) 
    114                 io_lock_file.close() 
    115                 os.unlink(lock_path) 
     83                os.close(fd) 
    11684        except OSError, e: 
    11785            if must_create and e.errno == errno.EEXIST: