コード例 #1
0
ファイル: game.py プロジェクト: wojtex/dvd-project-yellow
 def all_results(self):
     """
     Array of results of all queries in the chain.
     """
     while not self.ready:
         sleep(milliseconds(1))
     return self._all_results
コード例 #2
0
ファイル: game.py プロジェクト: wojtex/dvd-project-yellow
 def result(self):
     """
     Result of last query in the chain.
     """
     while not self.ready:
         sleep(milliseconds(1))
     return self._result
コード例 #3
0
ファイル: game.py プロジェクト: wojtex/dvd-project-yellow
 def result(self):
     """
     Returns the result (waits for completion if needed).
     :return:
     """
     while not self.checker(self.object):
         sleep(milliseconds(1))
     return self.result_getter(self.object)
コード例 #4
0
ファイル: test_time.py プロジェクト: Jijidici/python-sfml
def time():
    return dict(
        micro=sf.microseconds(5000000),
        milli=sf.milliseconds(5000),
        sec=sf.seconds(5))
コード例 #5
0
 def _connect_loop(self, connector, seconds):
     for i in range(int(seconds * 10)):
         if connector.is_connected: break
         sleep(milliseconds(100))
コード例 #6
0
    def test_notifications(self):
        """
        Server is notificating everybody about other client entrances on channel 12.
        """
        server = Server(lambda x: x == 1)

        def on_new_client(client_id):
            # notify other clients
            for cid in server.clients.keys():
                if cid == client_id: continue
                server.notify(cid, 12, {'new-client': client_id})

        server.set_accept_handler(on_new_client)

        consumer = Client(1)    # client wanting notification
        producer = Client(1)    # client making notification sending

        srv_th = Thread(target=Server.listen, args=(server, '127.0.0.1', 1234))
        srv_th.start()

        def stop_network(timeout):
            consumer.disconnect()
            producer.disconnect()
            server.close()
            srv_th.join(timeout=timeout)

        # setup consumer
        got_notification = False

        def on_notification(channel, data):
            if channel == 12 and 'new-client' in data:
                nonlocal got_notification
                got_notification = True
        consumer.set_notification_handler(12, on_notification)

        # connect consumer
        c = consumer.connect('127.0.0.1', 1234)
        self._connect_loop(c, 3.)
        try:
            self.assertTrue(c.is_connected)
        except AssertionError:
            stop_network(2.)
            raise

        # connected, so connect producer
        c = producer.connect('127.0.0.1', 1234)
        self._connect_loop(c, 3.)
        try:
            self.assertTrue(c.is_connected)
        except AssertionError:
            stop_network(2.)
            raise

        # we should get the notification right now
        for i in range(30):
            consumer.receive_all()
            if got_notification: break
            sleep(milliseconds(100))

        try:
            self.assertTrue(got_notification)
        except AssertionError:
            stop_network(2.)
            raise

        stop_network(2.)
        self.assertFalse(srv_th.is_alive())
コード例 #7
0
ファイル: test_clock.py プロジェクト: Jijidici/python-sfml
def test_restart(clock):
    clock.restart()

    assert clock.elapsed_time <= sf.milliseconds(10)