On Wednesday, January 18, 2017 at 2:12:35 PM UTC-8, Anthony wrote:
>
> A web2py controller is not like a Python module. It is meant to be 
> executed in a prepared environment to generate the response to an HTTP 
> request. Because the top level of the controller may include code you 
> wouldn't want executed unless proceeding with an HTTP request, it must 
> first be determined whether the requested function actually exists in the 
> file *before* executing it (in order to allow execution to be aborted in 
> case the function is not present). Also, when web2py compiles applications, 
> it creates a separate bytecode compiled file for each function in each 
> controller -- in order to do this, it must know the function names, again, 
> without executing the file (as the compilation process takes place outside 
> the environment of an HTTP request, and we don't want any side effects).
>
>
I see, thanks.  What kind of things can be usefully done at the top level 
that would cause problems outside the request environment?  Most of the 
stuff I see looking through the docs is stuff happening internally to 
controller functions, except for a small amount of setup stuff (like 
"service = Service()") that doesn't appear to have side effects.  Are there 
useful web2py design patterns that involve significant logic in the 
controller top-level?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to