Fix in session file locking
This commit is contained in:
parent
1024fe9e57
commit
a65f9b49eb
1 changed files with 17 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ from paramecio.citoplasma.keyutils import create_key_encrypt, create_key_encrypt
|
||||||
from bottle import request, response
|
from bottle import request, response
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import fcntl
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
|
@ -202,7 +203,23 @@ else:
|
||||||
path_cookie=config.session_opts['session.data_dir']+'/session_'+token
|
path_cookie=config.session_opts['session.data_dir']+'/session_'+token
|
||||||
|
|
||||||
with open(path_cookie, 'w') as f:
|
with open(path_cookie, 'w') as f:
|
||||||
|
|
||||||
|
#Lock file, if cannot lock wait
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
|
break
|
||||||
|
except IOError as e:
|
||||||
|
# raise on unrelated IOErrors
|
||||||
|
if e.errno != errno.EAGAIN:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
f.write(json.dumps(session))
|
f.write(json.dumps(session))
|
||||||
|
|
||||||
|
fcntl.flock(f, fcntl.LOCK_UN)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def generate_session():
|
def generate_session():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue