[Twisted-Python] deferLater with trial issue

Conway, Nicholas J Nick.Conway at wyss.harvard.edu
Wed May 23 15:30:45 MDT 2012


I have a class that needs to kick off a method the repeatedly gets call every so many seconds, lets say 2 seconds.

I chose to use task.deferLater to do this, but seems like LoopingCall gives similar results..

I've boiled it down to the following example
from twisted.internet import reactor, task
from twisted.trial import unittest

class MyLoop(object):
    def __init__(self):

    def updateParameters(self):
        d = task.deferLater(reactor, 2, self.dosomething)

    def dosomething(self):
        print "cool"

class LoopTestCase(unittest.TestCase):
    def setUp(self):
        self.cL = MyLoop()

    def test_dummy(self):
        d = defer.Deferred()
        d.addCallback(lambda x: x)
        return d  # return a deferred just in case but happens either way
MyLoop works when running normally with a reactor.run(), but when I try run this test, I get the following error:

Traceback (most recent call last):
Failure: twisted.trial.util.DirtyReactorAggregateError: Reactor was unclean.
DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
<DelayedCall 0x1018fbb90 [1.99891901016s] called=0 cancelled=0 Deferred.callback(None)>

So I don't fully understand what's going on to cause this.  Any pointers would be appreciated


-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20120523/3e0655d0/attachment-0001.html>

More information about the Twisted-Python mailing list