Ejemplo n.º 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"
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 4
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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 7
0
 def run(self, interval, fn, *args, **kwargs):
     while True:
         yield sleep(interval)
         yield fn(*args, **kwargs)
Ejemplo n.º 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))
Ejemplo n.º 9
0
 def dummy():
     yield sleep(1.0, reactor=clock)
     raise MyExc
Ejemplo n.º 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"