[Twisted-Python] Deferred question

Gabriel Rossetti gabriel.rossetti at arimaz.com
Tue Dec 9 04:09:10 EST 2008

Gabriel Rossetti wrote:
> Hello everyone,
> I have a question concerning defers, I have a service that needs to 
> query IO until it answers. The IO can be disconnected, connected but 
> off, connected and on; depending on the state I get different 
> exceptions. I wrote something like :
> def __requestId(self, _):
>        d = self.callPlugin(PLUGIN_NAME)
>        d.addCallback(self.__receivedAns)
>        d.addErrback(self.__requestId)
> The plugin makes the request in a thread and the deferred is returned 
> and called when either an answer is received or am exception is raised 
> (e.g. timeout, missing hardware, etc)
> This seams to work well, except that when I let the system run for a 
> long time without the hardware being present or off (several 
> hours/days) the memory consumption goes way up. I don' t really know 
> what is causing this, and I'm looking for possible reasons, so I was 
> wondering if maybe this could be what is causing the problem. It's 
> probably not that, because from what I understand it works like this :
>   1. the first request is made
>   2. there is a timeout or something that raises the exception
>   3. the errback gets called
>   4. it makes a new request
>   5. the deferred gets garbage collected
>   6. the new request follows the same path
> Can anyone confirm that this is correct, or are my defers somehow 
> staying alive and not being garbage collected?
> Thank you,
> Gabriel Rossetti
Forget it, I monkey-patched defer.Deferred to add __del__ to see if it 
was called, and it was, so they are getting destroyed...

More information about the Twisted-Python mailing list