Re: [web2py] Re: web2py exec in the new again

2011-02-02 Thread Jonathan Lundell
On Feb 2, 2011, at 2:08 PM, Anthony wrote: > Anyone? Is using local_import to import a class into a model/controller just > as safe as using 'from a import A' (i.e., in terms of memory leaks), or do > you have to use the Python import statement directly? It should be equivalent; both end up call

[web2py] Re: web2py exec in the new again

2011-02-02 Thread Anthony
Anyone? Is using local_import to import a class into a model/controller just as safe as using 'from a import A' (i.e., in terms of memory leaks), or do you have to use the Python import statement directly? On Tuesday, February 1, 2011 5:25:51 PM UTC-5, Anthony wrote: > But what if 'local_import

[web2py] Re: web2py exec in the new again

2011-02-02 Thread Massimo Di Pierro
On Feb 2, 1:26 am, cjrh wrote: > "Now now we know the cause, why doesn't it happen if you have a > module? The reason for that is that Python will do a trick when it > shuts down modules. It will override all global values that do not > begin with an underscore with None" Can you provide a proo

[web2py] Re: web2py exec in the new again

2011-02-02 Thread desfrenes
On 1 fév, 21:16, Massimo Di Pierro wrote: > In web2py you cannot store instances of objects into session. While > Armin makes it tool like this is a web2py problem this is more complex > and general than that. In Python if you pickle and object that is > instance of a class defined in /path1/mymo

[web2py] Re: web2py exec in the new again

2011-02-01 Thread cjrh
On Feb 1, 10:16 pm, Massimo Di Pierro wrote: > From the usual source: > http://lucumr.pocoo.org/2011/2/1/exec-in-python/ His post is pretty good and informative. > What would really be useful to us is an example of how to overcome > that problem by showing how to break those implicit self refere

[web2py] Re: web2py exec in the new again

2011-02-01 Thread Massimo Di Pierro
There is no problem if they have no __del__ method. On Feb 1, 5:24 pm, Jonathan Lundell wrote: > On Feb 1, 2011, at 12:16 PM, Massimo Di Pierro wrote: > > > > > I agree with Armin that in the case of exec (and web2py uses exec), > > the self references are created whether you want them or not. T

[web2py] Re: web2py exec in the new again

2011-02-01 Thread Massimo Di Pierro
Not quite like that. It is more like (web2py specific): "Do not declare classes with a __del__ method in web2py models or controllers or instances of those classes will cause memory leaks" AND (for any python program) "Do not declare classes with a __del__ method in any Python program unless you

[web2py] Re: web2py exec in the new again

2011-02-01 Thread Massimo Di Pierro
You are correct. There ar no problems using trunk (and future web2py versions) if classes have no __del__ method. On Feb 1, 5:00 pm, Anthony wrote: > On Tuesday, February 1, 2011 3:16:12 PM UTC-5, Massimo Di Pierro wrote: > > In web2py you cannot store instances of objects into session. While > >

[web2py] Re: web2py exec in the new again

2011-02-01 Thread VP
If what I thought above is true, a warning like this sufficient: "Global objects/variables in controllers might (will?) cause memory leaks". If this is what the criticism of web2py amounts to, I think it's a storm in a tea cup.

[web2py] Re: web2py exec in the new again

2011-02-01 Thread VP
It's interesting to note that even the variable "c" in my example above is properly destroyed with execfile('test.py', {}). What does this mean? I think this means that YES you can define classes inside a web2py controller without memory leaks, as long as there are no global (within the controll

[web2py] Re: web2py exec in the new again

2011-02-01 Thread Anthony
On Tuesday, February 1, 2011 3:16:12 PM UTC-5, Massimo Di Pierro wrote: > In web2py you cannot store instances of objects into session. While > Armin makes it tool like this is a web2py problem this is more complex > and general than that. In Python if you pickle and object that is > instanc

[web2py] Re: web2py exec in the new again

2011-02-01 Thread VP
Maybe unnecessary, but here's another test: + In foo.py: class Foo(object): def __del__(self): print 'Deleted' def bar(self): print "bar::" b = Foo() def f(): print "local_func::" c = Foo() + In test.py: from foo import * a = Foo() a.bar() f() + Then,

[web2py] Re: web2py exec in the new again

2011-02-01 Thread Anthony
But what if 'local_import' is used (instead of 'from a import Foo') -- does local_import work the same as regular Python imports? On Tuesday, February 1, 2011 5:09:25 PM UTC-5, Massimo Di Pierro wrote: > I run this test (following Armin's example): > > # in file a.py > class Foo(object): >

[web2py] Re: web2py exec in the new again

2011-02-01 Thread Massimo Di Pierro
I run this test (following Armin's example): # in file a.py class Foo(object): def __del__(self): print 'Deleted' #in file b.py from a import A foo=Foo() #in file c.py execfile('b.py', {}) execfile('b.py', {}) execfile('b.py', {}) import gc gc.collect() running c.py printes Deleted

[web2py] Re: web2py exec in the new again

2011-02-01 Thread VP
One question: If I define a class externally, and use local_import to import it into controller or model, will it have these potential problems or not?