[Unresolved] webpy bug when using sessions with generator and normal function handlers

Source: Internet
Author: User
Tags finally block
Class count1: def get (Self): S. session. count + = 1 return STR (S. session. count) Class count2: def get (Self): S. session. count + = 1 yield STR (S. session. count)

With above two handlers differs only in the way returning information (the 2nd one being a generator), Web. py session actually works with the first one but not the second case.

Simple scenario is:

Web. PY uses "processor", similar to chain-of-responsibility in gof patterns, to add processing steps to the handler functions. session, implemented this way, saves session information automatically when the handler is called and finished:

# Session. PY l83 def _ processor (self, Handler): "" application processor to setup session for every request "self. _ cleanup () self. _ load () Try: Return handler () Finally: Self. _ save ()

In usual case (or: count1), then handler () callthe whole handler function and return the string as the result, which is fine. and the session object has all update in-place then _ save () ed in the Finally block.

In the generator (or, count2) case though, the handler () Only returns a generator object of count2.get (bound to some object) but the handler code is not actually started. therefore, when self. _ save () is being called, it's actually before the session counter
Update. web. PY then uses itertools. chain to unroll the generator and get all output to the client, after the handle_with_processors () call in application. PY line 279, which is all too late already.

I believe that the correct way is actually unroll the generator before returning from the handler () call (application. PY line 239, "Return self. handle ()"). but this hasn't been verified and I need insights onto this.

Link to issue on GitHub: https://github.com/webpy/webpy/issues/235

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.