views:

150

answers:

2

Hey,

I have a pretty intensive chat socket server written in Twisted Python, I start it using internet.TCPServer with a factory and that factory references to a protocol object that handles all communications with the client.

How should I make sure a protocol instance completely destroys itself once a client has disconnected?

I've got a function named connectionLost that is fired up once a client disconnects and I try stopping all activity right there but I suspect some reactor stuff (like twisted.words instances) keep running for obsolete protocol instances.

What would be the best approach to handle this?

Thanks!

A: 

ok, for sorting out this issue I have set a del method in the protocol class and I am now logging protocol instances that have not been garbage collected within 1 minute from the time the client has disconnected.

If anybody has any better solution I'll still be glad to hear about it but so far I have already fixed a few potential memory leaks using this log.

Thanks!

Saggi Malachi
A `__del__` method is a really bad idea. This will prevent cycles from being collected. See <http://docs.python.org/library/gc.html#gc.garbage>.
Glyph
A: 

Saggi,

Could you give more information on the code you used? Both the del method in the protocol class and your garbage collection?

Regards, Niklas

Niklas B