尝试呼叫自我时出现扭曲错误

时间:2016-04-16 19:29:33

标签: python twisted

当我运行我的监听器时,我得到一个奇怪的AssertionError。这个类中的if部分逻辑工作,我从本教程中获取了扭曲的代码: http://krondo.com/our-eye-beams-begin-to-twist/

 class controlListener(object):
         counter = 20
         def count(self):
             if self.counter == 0:
                 print "Killing Process"
                 reactor.stop()
             else:
                 print self.counter, '...'
                 self.counter -= 1
                 reactor.callLater(1, self.counter)

错误

 --- <exception caught here> ---
   File "/usr/lib/python2.7/dist-packages/twisted/internet/base.py", line 429, in _continueFiring
     callable(*args, **kwargs)
   File "sponzyTwisted.py", line 17, in count
reactor.callLater(1, self.counter)
   File "/usr/lib/python2.7/dist-packages/twisted/internet/base.py", line 705, in callLater
     assert callable(_f), "%s is not callable" % _f
  exceptions.AssertionError: 19 is not callable

1 个答案:

答案 0 :(得分:1)

您应该向callLater as seen in the docs提供可调用对象,而您提供简单的int counter。您应该将实际方法count作为可调用方传递,如下所示:

class controlListener(object):
         counter = 20
         def count(self):
             if self.counter == 0:
                 print "Killing Process"
                 reactor.stop()
             else:
                 print self.counter, '...'
                 self.counter -= 1
                 reactor.callLater(1, self.count)