[Twisted-Python] Re:how to pass on the connection failed or connection lost error

Jean-Paul Calderone exarkun at divmod.com
Fri Mar 6 07:56:04 EST 2009

On Thu, 5 Mar 2009 15:49:31 -0800 (PST), khawar hasham <hasham_james_007 at yahoo.com> wrote:
>I tried to use this suggestion but I could not make it work.
>here is the test I am using
>in my application class
>def callSend(self, msg):
>      plugin.send(msg)
>Now in plugin class
>def send(self, msg):
>      print 'before call'
>      threads.blockingCallFromThread(reactor, remotesend, msg)
>      print 'after call'
>def handleError(self, error):
>      error.raiseException()
>def remotesend(self, msg):
>     deferred = defer.Deferred()
>     reactor.connectTCP('localhost',9999,myfactory)
>     deffered.addErrback(self.handleError)
>     return deffered
>now myfactory class .. clientConnectionFailed
>def clientConnectionFailed(self, connector, reason):
>      reason.raiseException()
>now the problem is, code has become synchronous as code is waiting after threads.blockingCallFromThread, how to fire the defer returned from 'remotesend'. Do i need to fire it or twisted will take care of it.

You probably need to fire it.  You created it, so it's your responsibility.
I don't know when you want it to fire, though.  What is it supposed to

>I think I can't refer this deferred object since it is being passed to threads.blockingCallFromThread function on which I have no control.

Not only that, but you can't do anything with it outside the reactor thread.

>any suggestions

What do you want to happen?


More information about the Twisted-Python mailing list