Django1.1 file based session backend multi-threaded solution
Posted
by Satoru.Logic
on Stack Overflow
See other posts from Stack Overflow
or by Satoru.Logic
Published on 2010-04-30T15:15:25Z
Indexed on
2010/04/30
15:17 UTC
Read the original article
Hit count: 182
Hi, all.
I read django.contrib.sessions.backend.file
today, in the save
method of SessionStore
there is something as the following that's used to achieve multi-threaded saving integrity:
output_file_fd, output_file_name = tempfile.mkstemp(dir=dir,
prefix=prefix + '_out_')
renamed = False
try:
try:
os.write(output_file_fd, self.encode(session_data))
finally:
os.close(output_file_fd)
os.rename(output_file_name, session_file_name)
renamed = True
finally:
if not renamed:
os.unlink(output_file_name)
I don't quite understand how this solve the integrity problem.
© Stack Overflow or respective owner