[Twisted-Python] Twisted client memory leak

Diego Woitasen diego at woitasen.com.ar
Tue Jan 22 08:54:27 EST 2013


On Tue, Jan 22, 2013 at 10:38 AM, Marco Giusti <marco.giusti at gmail.com> wrote:
> On Tue, Jan 22, 2013 at 10:18:13AM -0300, Diego Woitasen wrote:
>> Here is the server code if you want to have a test:
> [cut]
>>
>> Thanks!
>>
>> On Tue, Jan 22, 2013 at 10:06 AM, Diego Woitasen <diego at woitasen.com.ar> wrote:
>> > I have an Twisted client app that makes hundreds of connections per
>> > minute. I discover that I have a memory leak un my app and I'm almost
>> > sure that is related to the ClientFactory() derived class that is
>> > never deleted.
>> >
>> > I reproduce the problem with a modification of Echo client example
>> > from Twisted documentation:
>> >
> [cut]
>> >
>> > With this code I discover that the instances of EchoClientFactory()
>> > are only deleted when the program shutdowns. They are not deleted when
>> > the connections finish. I haven't found in the documentation if I need
>> > to do some to get factory instances deleted.
>
> Add the following lines and see yourself, the factories are deleted as
> aspected:
>
>         import gc
>
>         def collect():
>             gc.collect()
>
>         signal.signal(signal.SIGUSR1,
>                 lambda s, f: reactor.callLater(0.001, collect)
>
> m.
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Ok, that's work. Thanks.

My question is now, why is this done automatically for EchoProtocol()
and not for EchoFactory()? Looks like the references are dropped why
Python is taking too much time to frees the memory.

An explanation around this is welcome :)

Regards,
   Diego

--
Diego Woitasen



More information about the Twisted-Python mailing list