[Twisted-Python] how manual run LoopingCall.f
![](https://secure.gravatar.com/avatar/a6cebefaa4a78d751774d0809b6b95b6.jpg?s=120&d=mm&r=g)
I use _threadedselect reactor. My waker its one line: eventmodule.post(eventmodule.Event(TWISTEDEVENT, iterateTwisted=func)) its send event, to pygame queue. My pygame loop: class PygameController(object): _tick = Tick() def _eventIterator(self): while True: if self._ticking: yield eventmodule.poll() else: yield eventmodule.wait() def run(self): for event in self._eventIterator(): if event.type == NOEVENT: self.manager.post(self._tick) continue elif event.type == TWISTEDEVENT: event.iterateTwisted() if not reactor.running: break continue ... When I need to quickly perform some function, I set the parameter PygameController._ticking to True, and my manager call some function. Its work. When I need to perform some function with a time interval of more than one second, I use LoopingCall. Its work. When I need to perform some function with a time interval of less than one second, LoopingCall too slow. I try use my ticking, but for function is not executed too often, I used the following code: def some_function(self): looping_instance = self.looping call = looping_instance.call if call and call.time - call.seconds() <= 0: looping_instance() but I get this traceback when I stop looping (LoopingCall.stop()): File "/usr/lib64/python2.6/site-packages/twisted/internet/base.py", line 779, in runUntilCurrent call.func(*call.args, **call.kw) File "/usr/lib64/python2.6/site-packages/twisted/internet/task.py", line 196, in __call__ d.addErrback(eb) File "/usr/lib64/python2.6/site-packages/twisted/internet/defer.py", line 199, in addErrback errbackKeywords=kw) File "/usr/lib64/python2.6/site-packages/twisted/internet/defer.py", line 181, in addCallbacks self._runCallbacks() --- <exception caught here> --- File "/usr/lib64/python2.6/site-packages/twisted/internet/defer.py", line 323, in _runCallbacks self.result = callback(self.result, *args, **kw) File "/usr/lib64/python2.6/site-packages/twisted/internet/task.py", line 191, in eb d.errback(failure) exceptions.AttributeError: 'NoneType' object has no attribute 'errback'
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
On Dec 28, 2009, at 8:05 AM, ploutosss ploutosss wrote:
When I need to perform some function with a time interval of less than one second, LoopingCall too slow.
LoopingCall was originally designed for playback of voice samples, in an application which did that once every 10ms, or 0.01 seconds. It should really be fast enough for you: if it is really too slow, I am guessing that something else is wrong.
This example isn't complete, so I am not sure what the problem is, but I can guess that 'looping_instance' is a LoopingCall instance. You should not be calling it using __call__ (really, this method is just a cute hack so that the LoopingCall instance can be passed directly to callLater, and show up in the DelayedCall repr, among other things), you should be using its "start" method. Good luck!
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
On Dec 28, 2009, at 8:05 AM, ploutosss ploutosss wrote:
When I need to perform some function with a time interval of less than one second, LoopingCall too slow.
LoopingCall was originally designed for playback of voice samples, in an application which did that once every 10ms, or 0.01 seconds. It should really be fast enough for you: if it is really too slow, I am guessing that something else is wrong.
This example isn't complete, so I am not sure what the problem is, but I can guess that 'looping_instance' is a LoopingCall instance. You should not be calling it using __call__ (really, this method is just a cute hack so that the LoopingCall instance can be passed directly to callLater, and show up in the DelayedCall repr, among other things), you should be using its "start" method. Good luck!
participants (2)
-
Glyph Lefkowitz
-
ploutosss ploutosss