[Twisted-web] liveevil problem: nested functions get lost

noema mailinglists at shechen.at
Fri Feb 25 22:47:39 MST 2005



I think I encountered similar symptoms once and after quite some time of 
confusion I concluded that it must have to do with python's garbage 
collector. It seemed to me that there needs to be something refereced in 
the do_something() method to prevent it from being wiped before the call 
comes back from the client.

In most of my code (like in the following example) I have a referenced 
variable and therefore it works. But I totally agree this behavior 
should be documented otherwise it can be very frustrating.

#noema


This structure works resolves correctly:

class Blah(rend.Page):
     def render_blah(self, ctx, data):
         def do_something(client):
             some_variable
             client.alert("You will never see this message!")
         some_variable = None
         return ctx.tag.clear()[T.span(
             onclick=liveevil.handler(do_something))["Click me"]]



Federico Di Gregorio wrote:
> Hi all,
> 
> I don't know if this is a known problem or the way it is supposed to
> work but the following code results in a "lost" liveevil handler:
> 
> class Blah(rend.Page):
>     def render_blah(self, ctx, data):
>         def do_something(client):
>             client.alert("You will never see this message!")
>         return ctx.tag.clear()[T.span(
>             onclick=liveevil.handler(do_something))["Click me"]]
> 
> The do_something is not recognized as a closure (actually it is not :)
> so its "path" is saved away as module.do_something and does not get
> resolved at call time. I know about the identifier keyword something
> about it should probably be added to the docs. Maybe is would be even
> better (and safer) to remove the reflect part and use only the events.
> 
> federico
> 
> 
> 
> _______________________________________________
> Twisted-web mailing list
> Twisted-web at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
> 



More information about the Twisted-web mailing list