Cause of the problem
Because multiple threads read and write the session file at the same time causing the thread's behavior to be denied error, in order to avoid this problem, you can add some delay, or each thread has its own copy, and finally cover the unique session
Solution Solutions
- https://github.com/webpy/webpy/issues/191
- Https://github.com/webpy/webpy/issues/83
Method One:
Modify the session in session.py. The __setitem__ method of Diskstore
def __setitem__(self, Key, value): Path=Self._get_path (key) pickled=Self.encode (value)Try: tname = path+ "." + Threading.current_thread (). GetName () f= Open (Tname,'W') Try: F.write (pickled)finally: F.close () os.rename (tname, path) #atomary Operation exceptIOError:Pass
But it seems that under win rename does not seem to be able to directly overwrite the target file, so.
Method Two:
def __getitem__(self, Key): Path=Self._get_path (Key)ifos.path.exists (path): whileTrue:Try: Pickled=open (Path). Read ()returnself.decode (pickled)exceptEOFError:time.sleep (0.1) Else: RaiseKeyerror, key
web.py Eoferror exception resolution when using Session.diskstore to store session