[Twisted-Python] Re: what's wrong in my code?

wang wei wgwigw at gmail.com
Wed Jul 5 22:57:35 EDT 2006

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,

s = snmpFactory()
l = task.LoopingCall(s.readSnmpValue)

It's my first twisted program, thank for Jonathan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20060706/6dc7eef8/attachment.htm 

More information about the Twisted-Python mailing list