示例#1
0
def test_timeout_is_reached(clock):
    try:
        yield with_timeout(1.0, sleep(2.0, reactor=clock), reactor=clock)
    except Timeout:
        pass
    else:
        assert False, "Timeout should have been reached"
示例#2
0
    def run(self, other_actor):
        other_actor = lookup(other_actor) if isinstance(other_actor, str) else other_actor
        while True:
            dbg("sending greeting to %r" % (other_actor,))
            other_actor << ('hello!', self.ref)

            dbg("waiting for ack from %r" % (other_actor,))
            yield with_timeout(5.0, self.get('ack'))

            dbg("got 'ack' from %r; now sleeping a bit..." % (other_actor,))
            yield sleep(1.0)
示例#3
0
    def run(self):
        child = self.spawn(ExampleActor)

        while True:
            dbg("sending greeting to %r" % (child,))
            child << ('hello!', self.ref)

            dbg("waiting for ack from %r" % (child,))
            yield with_timeout(5.0, self.get('ack'))

            dbg("got 'ack' from %r; now sleeping a bit..." % (child,))
            yield sleep(1.0)
示例#4
0
文件: demoapp.py 项目: cordis/spinoff
    def run(self, monitor):
        monitor = MonitorClient.get(monitor)

        yield sleep(random.random() * 2.0)

        def report(*what):
            monitor << what

        monitor << ('up', self.ref)

        while True:
            for state in ['preparing', 'processing', 'cleaning up']:
                monitor << ('state', self.ref, state)
                yield sleep(3.0 + random.random())
                for action in ['hmm', 'ahaaa', 'got it']:
                    yield report('log', self.ref, action)

            if random.random() < 0:
                return
            else:
                monitor << ('state', self.ref, 'waiting')
                yield sleep(.3)
示例#5
0
    def run(self, monitor):
        monitor = MonitorClient.get(monitor)

        yield sleep(random.random() * 2.0)

        def report(*what):
            monitor << what

        monitor << ('up', self.ref)

        while True:
            for state in ['preparing', 'processing', 'cleaning up']:
                monitor << ('state', self.ref, state)
                yield sleep(3.0 + random.random())
                for action in ['hmm', 'ahaaa', 'got it']:
                    yield report('log', self.ref, action)

            if random.random() < 0:
                return
            else:
                monitor << ('state', self.ref, 'waiting')
                yield sleep(.3)
示例#6
0
    def close(self):
        log()

        self.sock.sendMultipart((self.our_addr, DISCONNECT))
        if not _actor.TESTING:
            # have to avoid this during testing, and it's not needed anyway;
            # during testing, since everything is running in the same thread with no remoting (by default)
            # this will unnecessarily give control back to the test which means stuff will happen in the middle
            # of closing.
            # XXX: this actually should be possible regardless of the above comment
            yield sleep(0)

        self._kill_queue()
        self._emit_termination_messages()
        self.sock.shutdown()
        self.sock = self.owner = None
示例#7
0
 def run(self, interval, fn, *args, **kwargs):
     while True:
         yield sleep(interval)
         yield fn(*args, **kwargs)
示例#8
0
 def __init__(self, *args, **kwargs):
     Trigger.__init__(self, *args, **kwargs)
     # the final callback will be invoked "a bit" later, thus allowing the invoker of `.callback(...)` to proceed.
     self.addCallback(lambda _: sleep(0))
示例#9
0
 def dummy():
     yield sleep(1.0, reactor=clock)
     raise MyExc
示例#10
0
def test_timeout_is_not_reached(clock):
    try:
        yield with_timeout(2.0, sleep(1.0, clock), reactor=clock)
    except Timeout:
        assert False, "Timeout should not have been reached"