Ticket #8616: session_file_read_write_locking.diff
File session_file_read_write_locking.diff, 1.4 KB (added by , 16 years ago) |
---|
-
django/contrib/sessions/backends/file.py
44 44 def load(self): 45 45 session_data = {} 46 46 try: 47 session_file = open(self._key_to_file(), "rb") 47 flags = os.O_RDONLY | getattr(os, 'O_BINARY', 0) 48 49 # Use atomic file locking if available 50 flags |= getattr(os, 'O_SHLOCK', 0) 51 52 fd = os.open(self._key_to_file(), flags) 53 session_file = os.fdopen(fd, "rb") 48 54 try: 49 55 try: 50 56 session_data = self.decode(session_file.read()) … … 52 58 self.create() 53 59 finally: 54 60 session_file.close() 55 except IOError:61 except (OSError, IOError): 56 62 pass 57 63 return session_data 58 64 … … 71 77 flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC | getattr(os, 'O_BINARY', 0) 72 78 if must_create: 73 79 flags |= os.O_EXCL 80 81 # Use atomic file locking if available 82 flags |= getattr(os, 'O_EXLOCK', 0) 83 74 84 # Because this may trigger a load from storage, we must do it before 75 85 # truncating the file to save. 76 86 session_data = self._get_session(no_load=must_create)