[Twisted-Python] returning value after addCallback
Ladislav Andel
ladaan at iptel.org
Thu Aug 9 08:42:50 EDT 2007
Hi,
you could tell me that I should stop programming since I don't know
properly OOP but
I quite need to sort out this problem.
Here is another piece of code I have problem with.
Please be patient with me.
Where is mistake in my code. It is not returning any reasonable result.
Thank you for help.
Lada
-------------------------------------- code
-------------------------------------------------
from twisted.internet import reactor, defer, threads
from siptest import siptest_f
test_opts =
{'username':'test','transport':'udp','localport':'5085','password':'test'}
domain = ['sip.1und1.de', 'sip.babble.net']
class PingTracker:
def __init__(self):
self.dns = None
self.sip = None
self.ping = None
def gotSipServerResults(self, domain, test_opts):
if domain:
return siptest_f(domain, test_opts)
raise ValueError("Error occured")
def checkSIP(self, domain, test_opts):
return threads.deferToThread(self.gotSipServerResults, domain,
test_opts)
def check(self, host, test_opts):
checks = []
#checks.append(checkDNS().addCallback(self.setDNSResult))
checks.append(self.checkSIP(host,
test_opts).addCallback(self.setSIPResult))
#checks.append(checkPing().addCallback(self.setPingResult))
return defer.gatherResults(checks)
def setDNSResult(self, result):
self.dns = result
def setSIPResult(self, result):
self.sip = result
def setPingResult(self, result):
self.ping = result
def SipCallback(self):
print self.sip
test = PingTracker()
d = test.check(domain[0], test_opts)
print d # this returns Deferred...
test.SipCallback() # this returns None
reactor.run()
More information about the Twisted-Python
mailing list