[Twisted-Python] protocol-factory question
Hi group, I'm new in this mailing list and in twisted... I want to ask you a question about twisted factory and protocols: I'm building a server that have to receive commands from some clients via TCP. So I wrote my Protocol class, and my Factory class. If I understood the behavior of this system, every time a client connects to my server, factory build a protocol instance and "attach" it to the client. So the client comunicates with that protocol instance, right? Now, when from protocol I call self.transport.loseConnection(in way to disconnnect itself), the client will be disconnected,but its protocol instance still lives on. What can I do to destroy protocol instance after its client disconnection? Because if I have a thousand of connection attempts, I'll have a thousand of protocol instances, with a lot of allocated resources I hope I've been clear enough, even if my english is far to be perfect :) Thanks a lot Luca
So I wrote my Protocol class, and my Factory class. If I understood the behavior of this system, every time a client connects to my server, factory build a protocol instance and "attach" it to the client. So the client comunicates with that protocol instance, right? Now, when from protocol I call self.transport.loseConnection(in way to disconnnect itself), the client will be disconnected,but its protocol instance still lives on. What can I do to destroy protocol instance after its client disconnection? Because if I have a thousand of connection attempts, I'll have a thousand of protocol instances, with a lot of allocated resources
Protocol instance will remain alive in your program if you keep a reference to it. By default it's not done within Twisted, so when the connection is closed, the protocol instance must be destroyed at the next garbage collect turn, without doing anything in your application. If you keep a reference to it (to have a list of connected clients for example), just remove your instance from this list in connectionLost. -- Thomas
participants (2)
-
Luca Politti -
Thomas Hervé