尝试调用自己时出现扭曲错误
Twisted error when trying to call self
当我 运行 我的听众时,我收到一个奇怪的 AssertionError。此 class 中的 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
您应该向 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)
当我 运行 我的听众时,我收到一个奇怪的 AssertionError。此 class 中的 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
您应该向 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)