[Twisted-Python] Explicit disconnect from pb

Rene Dudfield illumen at yahoo.com
Tue Jul 22 00:11:02 EDT 2003

Uwe C. Schroeder wrote:

>On Monday 21 July 2003 06:35 pm, Andrew Bennetts wrote:
>>On Mon, Jul 21, 2003 at 06:21:05PM -0700, Uwe C. Schroeder wrote:
>>>I looked qround, but I can't find any information on how to disconnect
>>>from a pb session without ending the client.
>>>I have a service which I'm connecting to. Some time later I want to
>>>disconnect from this service to free up ressources ( the service keeps
>>>database connections etc, and I want to get rid of them ).
>>>The only thing I have on the client side is a remotereference to the
>>>perspective instance. So how do I disconnect from something I don't have
>>>a reference to ? Somehow there must be something I can call to disconnect
>>>the session (and on the server side trigger the disconnect handlers)
>>This sounds related to this bug:
>>    http://twistedmatrix.com/bugs/issue62
>Yep, sound like it.
>What I just tried ( and what partially works, at least for my purpose) is to 
>have a perspective_disconnect method in the perspective class which just 
>free's up the ressources I want to get rid of. certainly the connection still 
>hangs around until I close the client. I my case droping the database 
>connection which is no longer in use is more of a concern, so that works for 
>me. (each client opens 2 database connections at startup - one is solely for 
>login and gui definitions and has no password, the second is started after 
>login. Therefor I don't need the first connection anymore. But I need to 
>close the db connection since this server is intended to serve possibly up to 
>500 clients at a time, which would be 500 useless db connections)
>	UC

I was asking a very similar question yesterday on irc.

My problem was if a client connects to the server and does nothing, how 
do I disconnect it if I want to(from the server).

Radix came up with the suggestion of
best idea I can think of is to only put a single method on your Root 
object which returns a Referenceable that has your "real" client interface
 implement a remote_login(self, clientobj) method on your pb.Root that 
returns a Referenceable that actually gives access to your app
 the client will need to implement a small Referenceable that implements 
`remote_ping' and it needs to pass it to that `login' method on the Root 
so it can get back the app interface object

That still doesn't allow you to take care of misbehaving clients which 
never make calls.  But it should allow you do disconnect clients which 
log in.  As it will allow you to ping it over pb occasionally to make 
sure it is still there.

More information about the Twisted-Python mailing list