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

khawar hasham hasham_james_007 at yahoo.com
Thu Mar 5 18:49:31 EST 2009


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):

Now in plugin class
def send(self, msg):
      print 'before call'
      threads.blockingCallFromThread(reactor, remotesend, msg)
      print 'after call'

def handleError(self, error):

def remotesend(self, msg):
     deferred = defer.Deferred()
     return deffered

now myfactory class .. clientConnectionFailed 
def clientConnectionFailed(self, connector, reason):

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.

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

any suggestions

--- On Wed, 3/4/09, twisted-python-request at twistedmatrix.com <twisted-python-request at twistedmatrix.com> wrote:
From: twisted-python-request at twistedmatrix.com <twisted-python-request at twistedmatrix.com>
Subject: Twisted-Python Digest, Vol 60, Issue 6
To: twisted-python at twistedmatrix.com
Date: Wednesday, March 4, 2009, 11:00 AM

Send Twisted-Python mailing list submissions to
	twisted-python at twistedmatrix.com

To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to
	twisted-python-request at twistedmatrix.com

You can reach the person managing the list at
	twisted-python-owner at twistedmatrix.com

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Twisted-Python digest..."

Today's Topics:

   1. Re: how to pass on the connection failed or	connection lost
      error (Jean-Paul Calderone)


Message: 1
Date: Wed, 4 Mar 2009 09:59:42 -0500
From: Jean-Paul Calderone <exarkun at divmod.com>
Subject: Re: [Twisted-Python] how to pass on the connection failed or
	connection lost error
To: twisted-python at twistedmatrix.com
	<20090304145942.12853.42253504.divmod.quotient.17917 at henry.divmod.com>
Content-Type: text/plain; format=flowed

On Wed, 4 Mar 2009 06:39:59 -0800 (PST), khawar hasham
<hasham_james_007 at yahoo.com> wrote:
>let me first explain the application that I am developing. I have an
application that will use the twisted part as a plugin. this twisted part will
act as server and as client both.
>my application call the plugin method to send data to server module using
connectTCP. now the problem is I can not pass on the connection failed exception
to my calling application.

Since you're running the reactor in one thread and the rest of your
application in another thread, your question is basically one of message
passing.  You've already found reactor.callFromThread which is good; I
think you just want the slightly more featureful version, available in
twisted.internet.threads, blockingCallFromThread.  This is implemented
in terms of callFromThread, but additionally allows the caller to get
the result of the function being called - including waiting on a Deferred
if the function being called returns one.  If you switch to this, then
you only need to make Plugin.clientsend return a Deferred which eventually
fires with a result or a Failure.



Twisted-Python mailing list
Twisted-Python at twistedmatrix.com

End of Twisted-Python Digest, Vol 60, Issue 6

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20090305/d03a3ea0/attachment.htm 

More information about the Twisted-Python mailing list