Re: [web2py] Re: Trunk new importer working?

85 views
Skip to first unread message

Jonathan Lundell

unread,
May 2, 2011, 6:16:41 PM5/2/11
to web2py-developers
On May 2, 2011, at 1:20 PM, pierreth wrote:
>
> How can I read a boolean like DEBUG set in models or controllers from
> a module located in gluon? This is an aspect I don't know how to
> implement.

I note that the proposed (real soon now...) thread-local storage for request "globals" would support stuff like this.

pierreth

unread,
May 2, 2011, 6:52:51 PM5/2/11
to web2py-developers
Is this mean that I will be able to read the boolean that I am talking
about from gluon.custom_import? If so, I will wait for the feature
before moving on the new functionality I want to offer.

Jonathan Lundell

unread,
May 2, 2011, 7:00:59 PM5/2/11
to web2py-d...@googlegroups.com

The idea is that there will be a request-specific (thread-local) object, accessible to gluon modules as well as application code. Its intended use is to give gluon modules access to the standard application-global items, like request and response, for general utility and to allow the use of T(), or a gluon variant thereof, in gluon modules.

However, there's no reason that it couldn't be used for other purposes as well. The app would have to be aware of it, and store a copy of its DEBUG (for example) in the object. We might want to give the object a Storage variable named something like app_settings, to avoid namespace conflict.

pierreth

unread,
May 2, 2011, 8:33:27 PM5/2/11
to web2py-developers
On 2 mai, 19:00, Jonathan Lundell <jlund...@pobox.com> wrote:
> The idea is that there will be a request-specific (thread-local) object, accessible to gluon modules as well as application code. Its intended use is to give gluon modules access to the standard application-global items, like request and response, for general utility and to allow the use of T(), or a gluon variant thereof, in gluon modules.
>
> However, there's no reason that it couldn't be used for other purposes as well. The app would have to be aware of it, and store a copy of its DEBUG (for example) in the object. We might want to give the object a Storage variable named something like app_settings, to avoid namespace conflict.

OK, this seems to be a great idea. I thought about an application
object to represent the application running on its own. This seems to
be an incarnation of this idea. This will avoid to use of passing in
parameter globals() to functions that does not look very nice. The
object you are talking is the bridge between in the application code
and gluon.

Cool.

pierreth

unread,
May 3, 2011, 8:24:56 PM5/3/11
to web2py-developers
I created a new version of the custom importer that track file
changes. I am waiting for new stuff Jonathan talks about for reading
the boolean switch.

Jonathan Lundell

unread,
May 3, 2011, 8:30:09 PM5/3/11
to web2py-d...@googlegroups.com

What do you think, Massimo? Are we ready for some thread-local logic? We can start slowly...

Massimo Di Pierro

unread,
May 3, 2011, 10:01:41 PM5/3/11
to web2py-d...@googlegroups.com
I am ready!

I just want to make sure everybody is aware that by doing this we give
up the possibility of using async servers and for me that ok (they
already have problems with connections pooliing as it is).
Flask has the same issue.

Massimo

> --
> mail from:GoogleGroups "web2py-developers" mailing list
> make speech: web2py-d...@googlegroups.com
> unsubscribe: web2py-develop...@googlegroups.com
> details : http://groups.google.com/group/web2py-developers
> the project: http://code.google.com/p/web2py/
> official : http://www.web2py.com/

Massimo Di Pierro

unread,
May 3, 2011, 10:01:53 PM5/3/11
to web2py-d...@googlegroups.com
Please send it to me when ready

Anthony

unread,
May 3, 2011, 11:16:46 PM5/3/11
to web2py-d...@googlegroups.com
On Tuesday, May 3, 2011 10:01:41 PM UTC-4, Massimo Di Pierro wrote:
I am ready!
I just want to make sure everybody is aware that by doing this we give  
up the possibility of using async servers and for me that ok (they  
already have problems with connections pooliing as it is).
 
Admittedly, I don't know a whole lot about this technically, but what are the implications? Aren't Nginx and Lighttpd async servers -- does that mean we couldn't use them with web2py? What are the implications for doing high concurrency apps like chat apps? If this will introduce any serious limitations, either now or in the future development of the framework, maybe we should get some feedback from the users list first.
 
Anthony

Massimo Di Pierro

unread,
May 4, 2011, 9:16:15 AM5/4/11
to web2py-d...@googlegroups.com
web2py uses the thread/threading modules inside and was designed with normal threading in mind. It is also based on wsgi which is also designed for multi-threading and not async in mind. Therefore I am not sure ow well it current works with async servers. Connection pooling for sure must be broken already on high traffic.

In the case of Nginx and Lightpd, there is no problem because although they server is async, they just pass the request via socket to rocket running on its own port.

Honestly I am not sure about nginx+uwsgi. I am not sure how that works inside.

Massimo


Massimo Di Pierro

unread,
May 4, 2011, 9:23:49 AM5/4/11
to web2py-d...@googlegroups.com
Taking a second look at nginx+uwsgi.

nginx receives requests in async mode and passes them long via socket to uwsgi.
uwsgi can run in prefork, threaded and async mode:
When running with Django, web2py and Flask you have to run uwsgi in preform mode because they are not async servers.

So this works fine and will continue to work fine.





On May 3, 2011, at 10:16 PM, Anthony wrote:

pierreth

unread,
May 4, 2011, 2:48:03 PM5/4/11
to web2py-developers
On 3 mai, 22:01, Massimo Di Pierro <massimo.dipie...@gmail.com> wrote:
> Please send it to me when ready
>

I am wondering how things should work. Is this code reloading should
be activated for each application individually? Or would it be better
to use a global switch?

I really need feedback. How do you think this should work?

Feed back on my work: code reloading is working pretty well. You can
edit and add files and the code reloading will automatically load the
changes. But it is not working very well when you change the structure
like if you transform a module in a package using the same name. I am
looking at this problem but already what I have now is really not bad
at all.

Martín Mulone

unread,
Jun 17, 2011, 7:55:44 AM6/17/11
to web2py-d...@googlegroups.com
Sorry to revive this topic, but I remember sometime ago until the last stable, there was an auto reload of the modules, using this new way of importing, how can enabled this again?.

2011/5/4 pierreth <pierre.t...@gmail.com>
--
mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details    : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official    : http://www.web2py.com/



--

Pierre Thibault

unread,
Jun 17, 2011, 9:41:33 AM6/17/11
to web2py-d...@googlegroups.com
2011/6/17 Martín Mulone <mulone...@gmail.com>

Sorry to revive this topic, but I remember sometime ago until the last stable, there was an auto reload of the modules, using this new way of importing, how can enabled this again?.


Hi Martin,

I changed the api to something I believe was more convenient. If you look in gulon/custom_import.py you find two methods for this task:

def is_tracking_changes():
   ...

def track_changes(track=True):
   ...

So you'll have to call track_changes somewhere in your code to start the tracking. is_tracking_changes gives the current tracking state. So add:

from gluon.custom_import import track_changes
track_changes()

Since you asked the question, how can we improve the documentation process of web2py so the new stuff it automatically documented? I propose that Massimo integrates new code at the same time than the doc. Any idea?
--


A+

-------------
Pierre
My blog and profile (http://pierrethibault.posterous.com)
YouTube page (http://www.youtube.com/user/tubetib)
Twitter (http://twitter.com/pierreth2)

Martín Mulone

unread,
Jun 17, 2011, 10:18:53 AM6/17/11
to web2py-d...@googlegroups.com
Thanks pierre,

2011/6/17 Pierre Thibault <pierre.t...@gmail.com>

--
mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/



--

Anthony

unread,
Jun 17, 2011, 10:45:07 AM6/17/11
to web2py-d...@googlegroups.com
On Friday, June 17, 2011 9:41:33 AM UTC-4, Pierre Thibault wrote:
2011/6/17 Martín Mulone <mulone...@gmail.com>
Sorry to revive this topic, but I remember sometime ago until the last stable, there was an auto reload of the modules, using this new way of importing, how can enabled this again?.


Hi Martin,

I changed the api to something I believe was more convenient. If you look in gulon/custom_import.py you find two methods for this task:

def is_tracking_changes():
   ...

def track_changes(track=True):
   ...

So you'll have to call track_changes somewhere in your code to start the tracking. is_tracking_changes gives the current tracking state. So add:

from gluon.custom_import import track_changes
track_changes()
 
So, as soon as you do track_changes(), all imports will automatically be reloaded if changed, or is there an additional step?
 
Thanks.
 
Anthony

Pierre Thibault

unread,
Jun 17, 2011, 10:50:46 AM6/17/11
to web2py-d...@googlegroups.com
2011/6/17 Anthony <abas...@gmail.com>


No. It affects all applications. It will reload the module if the file has changed after the call to track_changes.

Anthony

unread,
Jun 17, 2011, 11:22:39 AM6/17/11
to web2py-d...@googlegroups.com
Got it. Thanks.

On Friday, June 17, 2011 10:50:46 AM UTC-4, Pierre Thibault wrote:
2011/6/17 Anthony <abas...@gmail.com>
On Friday, June 17, 2011 9:41:33 AM UTC-4, Pierre Thibault wrote:
2011/6/17 Martín Mulone <mulo...@gmail.com>

Sorry to revive this topic, but I remember sometime ago until the last stable, there was an auto reload of the modules, using this new way of importing, how can enabled this again?.


Hi Martin,

I changed the api to something I believe was more convenient. If you look in gulon/custom_import.py you find two methods for this task:

def is_tracking_changes():
   ...

def track_changes(track=True):
   ...

So you'll have to call track_changes somewhere in your code to start the tracking. is_tracking_changes gives the current tracking state. So add:

from gluon.custom_import import track_changes
track_changes()
 
So, as soon as you do track_changes(), all imports will automatically be reloaded if changed, or is there an additional step?
 
Thanks.


No. It affects all applications. It will reload the module if the file has changed after the call to track_changes.

pbreit

unread,
Jun 17, 2011, 12:23:58 PM6/17/11
to web2py-d...@googlegroups.com
I'm confused. This is to get reload=True functionality in modules? It looks like that needs to go in the module itself? Is there any way to set it more globally like "if is_dev(): track_changes()"?

Is it track_changes() or track_changes(track=True)?

Pierre Thibault

unread,
Jun 17, 2011, 12:29:44 PM6/17/11
to web2py-d...@googlegroups.com
2011/6/17 pbreit <pbreit...@gmail.com>
I'm confused. This is to get reload=True functionality in modules? It looks like that needs to go in the module itself? Is there any way to set it more globally like "if is_dev(): track_changes()"?

Is it track_changes() or track_changes(track=True)?

--

I am sorry but I don't understand what you don't understand.

Calling track_changes() or track_changes(True) is the same since it is the default argument.

As I said it affects all applications.

Modules are reloaded at the next import statement if the module file has changed.

pbreit

unread,
Jun 17, 2011, 12:41:36 PM6/17/11
to web2py-d...@googlegroups.com
Is track_changes() roughly equivalent to local_import()'s "reload=True" argument?

Do I put track_changes() in my module or somewhere else?

Pierre Thibault

unread,
Jun 17, 2011, 12:59:35 PM6/17/11
to web2py-d...@googlegroups.com
2011/6/17 pbreit <pbreit...@gmail.com>

Is track_changes() roughly equivalent to local_import()'s "reload=True" argument?

Mostly. I think local_import with reload=True will reload the module even if it does have changes.

track_changes loads nothing. You still have to load with a standard import statement. local_import is usefully for compatibility. It is better to use standard imports.
 

Do I put track_changes() in my module or somewhere else?

It is good thing to put it at the beginning of your app like in the first model executed so it can affect the next import statements. It can be used anywhere.

Martín Mulone

unread,
Jun 17, 2011, 2:48:19 PM6/17/11
to web2py-d...@googlegroups.com
Is working I made something like this:

from gluon.custom_import import track_changes

if current.app.settings.developer:
    track_changes()    

2011/6/17 Pierre Thibault <pierre.t...@gmail.com>
--
mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
Reply all
Reply to author
Forward
0 new messages