當前位置: 首頁>>代碼示例>>Python>>正文


Python SimpleServer.shutdown方法代碼示例

本文整理匯總了Python中pelita.simplesetup.SimpleServer.shutdown方法的典型用法代碼示例。如果您正苦於以下問題:Python SimpleServer.shutdown方法的具體用法?Python SimpleServer.shutdown怎麽用?Python SimpleServer.shutdown使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pelita.simplesetup.SimpleServer的用法示例。


在下文中一共展示了SimpleServer.shutdown方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_simple_failing_bots

# 需要導入模塊: from pelita.simplesetup import SimpleServer [as 別名]
# 或者: from pelita.simplesetup.SimpleServer import shutdown [as 別名]
    def test_simple_failing_bots(self):
        layout = """
        ##########
        #        #
        #0  ..  1#
        ##########
        """
        server = SimpleServer(layout_string=layout, rounds=5, players=2)

        for bind_address in server.bind_addresses:
            assert bind_address.startswith("tcp://")

        client1_address = server.bind_addresses[0].replace("*", "localhost")
        client2_address = server.bind_addresses[1].replace("*", "localhost")

        class FailingPlayer:
            def _set_initial(self, dummy, dummy2):
                pass
            def _set_index(self, dummy):
                pass
            def _get_move(self, universe, game_state):
                pass

        client1 = SimpleClient(SimpleTeam("team1", SteppingPlayer("^>>v<")), address=client1_address)
        client2 = SimpleClient(SimpleTeam("team2", FailingPlayer()), address=client2_address)

        client1.autoplay_process()
        client2.autoplay_process()
        server.run()
        server.shutdown()
開發者ID:ASPP,項目名稱:pelita,代碼行數:32,代碼來源:test_simplesetup.py

示例2: test_failing_bots_do_not_crash_server

# 需要導入模塊: from pelita.simplesetup import SimpleServer [as 別名]
# 或者: from pelita.simplesetup.SimpleServer import shutdown [as 別名]
    def test_failing_bots_do_not_crash_server(self):
        layout = """
        ##########
        #        #
        #0  ..  1#
        ##########
        """
        server = SimpleServer(layout_string=layout, rounds=5, players=2, timeout_length=0.3)

        for bind_address in server.bind_addresses:
            assert bind_address.startswith("tcp://")

        client1_address = server.bind_addresses[0].replace("*", "localhost")
        client2_address = server.bind_addresses[1].replace("*", "localhost")

        class ThisIsAnExpectedException(Exception):
            pass

        class FailingPlayer(AbstractPlayer):
            def get_move(self):
                raise ThisIsAnExpectedException()
        old_timeout = pelita.simplesetup.DEAD_CONNECTION_TIMEOUT
        pelita.simplesetup.DEAD_CONNECTION_TIMEOUT = 0.3

        client1 = SimpleClient(SimpleTeam("team1", FailingPlayer()), address=client1_address)
        client2 = SimpleClient(SimpleTeam("team2", FailingPlayer()), address=client2_address)

        client1.autoplay_process()
        client2.autoplay_process()
        server.run()
        server.shutdown()

        pelita.simplesetup.DEAD_CONNECTION_TIMEOUT = old_timeout
開發者ID:ASPP,項目名稱:pelita,代碼行數:35,代碼來源:test_simplesetup.py

示例3: test_simple_game

# 需要導入模塊: from pelita.simplesetup import SimpleServer [as 別名]
# 或者: from pelita.simplesetup.SimpleServer import shutdown [as 別名]
    def test_simple_game(self):
        layout = """
        ##########
        #        #
        #0  ..  1#
        ##########
        """
        server = SimpleServer(
            layout_string=layout,
            rounds=5,
            players=2,
            bind_addrs=(
                "ipc:///tmp/pelita-testplayer1-%s" % uuid.uuid4(),
                "ipc:///tmp/pelita-testplayer2-%s" % uuid.uuid4(),
            ),
        )

        for bind_address in server.bind_addresses:
            self.assertTrue(bind_address.startswith("ipc://"))

        client1_address = server.bind_addresses[0]
        client2_address = server.bind_addresses[1]

        client1 = SimpleClient(SimpleTeam("team1", RandomPlayer()), address=client1_address)
        client2 = SimpleClient(SimpleTeam("team2", RandomPlayer()), address=client2_address)

        client1.autoplay_process()
        client2.autoplay_process()
        server.run()
        server.shutdown()
開發者ID:nwilbert,項目名稱:pelita,代碼行數:32,代碼來源:test_simplesetup.py

示例4: test_simple_remote_game

# 需要導入模塊: from pelita.simplesetup import SimpleServer [as 別名]
# 或者: from pelita.simplesetup.SimpleServer import shutdown [as 別名]
    def test_simple_remote_game(self):
        layout = """
        ##########
        #        #
        #0  ..  1#
        ##########
        """
        server = SimpleServer(layout_string=layout, rounds=5, players=2)

        for bind_address in server.bind_addresses:
            assert bind_address.startswith("tcp://")

        client1_address = server.bind_addresses[0].replace("*", "localhost")
        client2_address = server.bind_addresses[1].replace("*", "localhost")

        client1 = SimpleClient(SimpleTeam("team1", SteppingPlayer("^>>v<")), address=client1_address)
        client2 = SimpleClient(SimpleTeam("team2", SteppingPlayer("^<<v>")), address=client2_address)

        client1.autoplay_process()
        client2.autoplay_process()
        server.run()
        server.shutdown()
開發者ID:ASPP,項目名稱:pelita,代碼行數:24,代碼來源:test_simplesetup.py

示例5: test_remote_game

# 需要導入模塊: from pelita.simplesetup import SimpleServer [as 別名]
# 或者: from pelita.simplesetup.SimpleServer import shutdown [as 別名]
def test_remote_game():
    remote = [libpelita.get_python_process(), '-m', 'pelita.scripts.pelita_player', '--remote']
    remote_stopping = remote + ['pelita/player/StoppingPlayer', 'tcp://127.0.0.1:52301']
    remote_food_eater = remote + ['pelita/player/FoodEatingPlayer', 'tcp://127.0.0.1:52302']

    remote_procs = [Popen_autokill(args) for args in [remote_stopping, remote_food_eater]]

    layout = """
        ##########
        #        #
        #0  ..  1#
        ##########
        """
    server = SimpleServer(layout_string=layout, rounds=5, players=2,
                          bind_addrs=['remote:tcp://127.0.0.1:52301', 'remote:tcp://127.0.0.1:52302'])

    server.run()
    server.shutdown()

    assert server.game_master.game_state['team_wins'] == 1

    server = SimpleServer(layout_string=layout, rounds=5, players=2,
                          bind_addrs=['remote:tcp://127.0.0.1:52302', 'remote:tcp://127.0.0.1:52301'])

    server.run()
    server.shutdown()

    assert server.game_master.game_state['team_wins'] == 0

    server = SimpleServer(layout_string=layout, rounds=5, players=2,
                          bind_addrs=['remote:tcp://127.0.0.1:52301', 'remote:tcp://127.0.0.1:52302'])

    server.run()
    server.shutdown()

    assert server.game_master.game_state['team_wins'] == 1

    # terminate processes
    [p.terminate() for p in remote_procs]
    for p in remote_procs:
        assert p.wait(2) is not None
開發者ID:ASPP,項目名稱:pelita,代碼行數:43,代碼來源:test_pelitagame.py


注:本文中的pelita.simplesetup.SimpleServer.shutdown方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。