2016-04-16 6 views
1

リスナーを実行するときに私が奇妙な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) 

あなたはcallLateras seen in the docsに呼び出し可能オブジェクトを提供することになっている

--- <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

エラー、および代わりに単純なint counterを提供しています。

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) 
+0

ザッツは素晴らしい、それは動作しますが、printStuff反応器へのcontrolListener doesntのパスの優先順位:あなたはそうのように、呼び出し可能としてあなたの実際の方法countを渡す必要があります。間違ったコールバックを使用していますか?私は1つのイテレーションを行い、次に何か他のものに渡すように、コントロールのリスナーのようなIDを使用します。 –

+1

コールバックは私にとって正しいと思われますが、私はTwistedで経験していません。 'reactor.callWhenRunning(controlListener()。count)'を呼び出すだけです。 – miradulo

関連する問題