thanks for help, I will read the documents of smart-questions soon:)<br>last night I read the twisted's book on the its web site, and I think there are 2 major mistake there. 1. the defer should not be inintinitialized in the __init__ phase, that's easy to understood why there are AlreadCalledError. 2. twisted use task to run the loop. :D
<br>that's a sample code here.<br><br>from twisted.internet import reactor, defer, task<br>class snmpFactory:<br> def __init__(self): <br><br> def readValue(self):<br> self.deferred = defer.Deferred()<br>
vol = readValue(self.voltageIp, voltageOid)<br> temp = readValue(self.powerIp, temperatureOid)<br> reactor.callLater(0, self.handleResult, (vol, temp))<br> return self.deferred<br> def handleResult(self, (vol, temp)):
<br> slice = time.strftime("%H:%M:%S")<br> print slice, ' the voltage is %s\nthe temperature is %s' % (vol,<br>temp)<br><br>s = snmpFactory()<br>l = task.LoopingCall(s.readSnmpValue)<br>l.start(2)<br>
reactor.run()<br><br>It's my first twisted program, thank for Jonathan.