[Twisted-web] Athena LiveElement: how to putChild under unique session URL?

Paul Reznicek maillists at ivsn.com
Wed Apr 22 13:29:23 EDT 2009

Werner Thie wrote:
> Paul Reznicek wrote:
>> glyph at divmod.com wrote:
>>> On 21 Apr, 08:57 pm, maillists at ivsn.com wrote:
>>>> Hello All,
>>>> LiveElement is fantastic, but I'm too stupid to find out,
>>>> how to put temporary page under sessiop URL...
>>>> This work for js modules at start like:
>>>>    http://localhost:8080/user/<HASH clientID>/jsmodule/athena_test
>>>> I'd like to add temporary during run time something like:
>>>>    http://localhost:8080/user/<HASH clientID>/your_data
>>>> page or staticFile, which should exists only few minutes.
>> Caveat is, that instances of gone clients are keeping in memory. Is there
>> a way to find out, that a client is gone (closed browser or switched to
>> other site)?
> Welcome to the land of garbage collecting languages... What was the 
> losing memory of the C++ ages is now the not releasing memory because of 
> noncollectable garbage and server processes eating all the memory the 
> machine has. I had to learn it the hard way but NEVER ever store a 
> reference to something like sessions, mind or the the hierarchy of your 
> LiveElements unless you're prepared to handle the breakup of the 
> reference at cleanup time. Also keep in mind that the object hierarchy 
> of client and server must be in sync or you're risking that the detach 
> functionality does not work as advertised. Please see the 
> detach/detached functionality in athena.py
> class thePage(athena.LivePage):
>   def beforeRender(self, ctx):
>            :
>     d = self.notifyOnDisconnect()
>     d.addErrback(self.disconn)
>   def disconn(self, reason):
>     """
>     we will be called back when the client disconnects, just iterate
>     over all children and call a disconnected func if available
>     """
>     for child in self.liveFragmentChildren:
>       if hasattr(child, 'disconnected'):
>         child.disconnected(reason);
> Werner

Great! Exactly what I needed to remove cleanly user with loosed connection.
Together with Glyph's "_self.page.putChild('your_data', YourDataResource())_"
all my problems are solved.

BTW: How to use *detach* and *detached* in LiveElement? I didn't find out...

Many thanks, Paul

More information about the Twisted-web mailing list