[Twisted-Python] Re: what's wrong in my code?
thanks for help, I will read the documents of smart-questions soon:) 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 that's a sample code here. from twisted.internet import reactor, defer, task class snmpFactory: def __init__(self): def readValue(self): self.deferred = defer.Deferred() vol = readValue(self.voltageIp, voltageOid) temp = readValue(self.powerIp, temperatureOid) reactor.callLater(0, self.handleResult, (vol, temp)) return self.deferred def handleResult(self, (vol, temp)): slice = time.strftime("%H:%M:%S") print slice, ' the voltage is %s\nthe temperature is %s' % (vol, temp) s = snmpFactory() l = task.LoopingCall(s.readSnmpValue) l.start(2) reactor.run() It's my first twisted program, thank for Jonathan.
participants (1)
-
wang wei