web.py Eoferror exception resolution when using Session.diskstore to store session

Source: Internet
Author: User

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

    1. https://github.com/webpy/webpy/issues/191
    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.