Ejemplo n.º 1
0
def test_timer():
    global test_timer_var
    test_timer_var = False

    def set_timer_var():
        global test_timer_var
        test_timer_var = True
    capnp.getTimer().after_delay(1).then(set_timer_var).wait()

    assert test_timer_var is True

    test_timer_var = False
    promise = capnp.Promise(0).then(lambda x: time.sleep(.1)).then(lambda x: time.sleep(.1)).then(lambda x: set_timer_var())

    canceller = capnp.getTimer().after_delay(1).then(lambda: promise.cancel())

    joined = capnp.join_promises([canceller, promise])
    joined.wait()
Ejemplo n.º 2
0
def test_timer():
    global test_timer_var
    test_timer_var = False

    def set_timer_var():
        global test_timer_var
        test_timer_var = True

    capnp.getTimer().after_delay(1).then(set_timer_var).wait()

    assert test_timer_var is True

    test_timer_var = False
    promise = capnp.Promise(0).then(lambda x: time.sleep(.1)).then(
        lambda x: time.sleep(.1)).then(lambda x: set_timer_var())

    canceller = capnp.getTimer().after_delay(1).then(lambda: promise.cancel())

    joined = capnp.join_promises([canceller, promise])
    joined.wait()
Ejemplo n.º 3
0
def test_then_args():
    capnp.Promise(0).then(lambda x: 1)

    with pytest.raises(Exception):
        capnp.Promise(0).then(lambda: 1)

    with pytest.raises(Exception):
        capnp.Promise(0).then(lambda x, y: 1)

    capnp.getTimer().after_delay(1).then(lambda: 1)  # after_delay is a VoidPromise

    with pytest.raises(Exception):
        capnp.getTimer().after_delay(1).then(lambda x: 1)

    client = capability.TestInterface._new_client(Server())

    client.foo(i=5).then(lambda x: 1)

    with pytest.raises(Exception):
        client.foo(i=5).then(lambda: 1)

    with pytest.raises(Exception):
        client.foo(i=5).then(lambda x, y: 1)
Ejemplo n.º 4
0
def test_then_args():
    capnp.Promise(0).then(lambda x: 1)

    with pytest.raises(Exception):
        capnp.Promise(0).then(lambda: 1)

    with pytest.raises(Exception):
        capnp.Promise(0).then(lambda x, y: 1)

    capnp.getTimer().after_delay(1).then(lambda: 1)  # after_delay is a VoidPromise

    with pytest.raises(Exception):
        capnp.getTimer().after_delay(1).then(lambda x: 1)

    client = capability.TestInterface._new_client(Server())

    client.foo(i=5).then(lambda x: 1)

    with pytest.raises(Exception):
        client.foo(i=5).then(lambda: 1)

    with pytest.raises(Exception):
        client.foo(i=5).then(lambda x, y: 1)
Ejemplo n.º 5
0
 def longRunning(self, **kwargs):
     return capnp.getTimer().after_delay(1 * 10**9)
Ejemplo n.º 6
0
 def subscribeStatus(self, subscriber, **kwargs):
     return capnp.getTimer().after_delay(10**9) \
         .then(lambda: subscriber.status(True)) \
         .then(lambda _: self.subscribeStatus(subscriber))
Ejemplo n.º 7
0
            except EOFError:
                break
            time.sleep(.01)

    command_thread = threading.Thread(target=get_input)
    command_thread.daemon = True
    quit = False

    print('ChatRoom v0.1')
    print('Commands: {}'.format(', '.join(
        ['"%s"' % command for command in user.commands.list])))
    command_thread.start()

    while not quit:
        try:
            command = command_queue.get(False)
        except queue.Empty:
            command = None

        if command:
            with command_lock:
                try:
                    user.commands.evaluate(command)
                except ValueError as exception:
                    print('ERROR: %s' % exception.message)

        capnp.getTimer().after_delay(.01 * 10**9).wait()

        if not command_thread.is_alive():
            quit = True
Ejemplo n.º 8
0
 def longRunning(self, **kwargs):
     return capnp.getTimer().after_delay(3 * 10**9)
Ejemplo n.º 9
0
 def subscribeStatus(self, subscriber, **kwargs):
     return capnp.getTimer().after_delay(10**9) \
         .then(lambda: subscriber.status(True)) \
         .then(lambda _: self.subscribeStatus(subscriber))
Ejemplo n.º 10
0
 def make_timeout(self):
     if self._timeout > 0:
         self._timeout_prom = capnp.getTimer().after_delay(
             self._timeout * 10**9).then(lambda: exit(0))