[Twisted-Python] Using deferreds when writing across unreliable network
johnaherne at rocs.co.uk
Fri Oct 10 06:21:57 EDT 2008
I have been trying out twisted(2.5 for python 2.4 XPSP2) over the past few
weeks and have some code running connecting with some mobile devices over
GPRS. It works. But I am having problems with deferreds - which I find
tricky to understand.
I have setup a tcpserver which the mobile devices connect to and I send
answers back and occasionally unsolicited messages out.
I have made an assumption that I should use a defer to write back across the
network. Maybe I am wrong.
I have a function in which I set up the transport.write to send a message
out. This I make a deferred and return the deferred and add my callBack and
errBack functions. I can see them when I print out the callbacks so I know
they are there.
As far as I can see from my logs, the deferred runs but neither the callback
nor the errback are fired. Possibly an error occurs that stops them but I
have not yet found a way to pin this down. I see there is a setDebugging
option but I have not yet worked out how I would use this.
So before I start trying any more incorrect assumptions, what I would like
to confirm is that I should expect my callback or errback functions to be
called automatically when my deferred has executed and returned.
If successful, it would return fairly promptly. If it fails it could take a
number of minutes to fail. But that is another problem.
So should my callback or errback fire without me having to initiate any
action other than setting up the deferred. And should I be using a deferred
at all for this situation.
If I know that the basis of what I am doing is correct and I am still having
problems I can try and put together a small bit of code that reproduces the
problem on the assumption that my code is probably wrong.
Thanks for any pointers. I'm afraid that everytime I read the documentation
on deferreds and go through the examples on using them I come to different
conclusions on what I should be doing. So any help would be much
One example I looked at was the getPage example. Apart from doing a read it
seems to be much along the lines of what I want to do. I am writing using
straight TCP rather than HTTP. But that example fires the callback and
errback without any problems. So it makes me think that my deferreds have
something wrong with them.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python