From c788b253fbf27706d0cac693f6c02ac806376c5a Mon Sep 17 00:00:00 2001 From: Dong Yan Date: Wed, 27 Dec 2017 01:04:09 +0800 Subject: [PATCH] show the stdout of player.py for debugging --- AlphaGo/play.py | 17 ++++++++++++----- AlphaGo/player.py | 12 ++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/AlphaGo/play.py b/AlphaGo/play.py index 884d2ab..038953f 100644 --- a/AlphaGo/play.py +++ b/AlphaGo/play.py @@ -54,11 +54,6 @@ if __name__ == '__main__': # print "kill the old pyro4 name server, the return code is : " + str(kill_old_server.wait()) # time.sleep(1) - # start a name server to find the remote object - # start_new_server = subprocess.Popen(['pyro4-ns', '&']) - # print "Start Name Sever : " + str(start_new_server.pid) # + str(start_new_server.wait()) - # time.sleep(1) - # start a name server if no name server exists if len(os.popen('ps aux | grep pyro4-ns | grep -v grep').readlines()) == 0: start_new_server = subprocess.Popen(['pyro4-ns', '&']) @@ -91,11 +86,23 @@ if __name__ == '__main__': ['python', '-u', 'player.py', '--game=' + args.game, '--role=' + black_role_name, '--checkpoint_path=' + str(args.black_weight_path), '--debug=' + str(args.debug)], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + bp_output = black_player.stdout.readline() + bp_message = bp_output + while bp_output != '' and "Start requestLoop" not in bp_output: + bp_output = black_player.stdout.readline() + bp_message += bp_output + print("============ " + black_role_name + " message ============" + "\n" + bp_message), white_player = subprocess.Popen( ['python', '-u', 'player.py', '--game=' + args.game, '--role=' + white_role_name, '--checkpoint_path=' + str(args.white_weight_path), '--debug=' + str(args.debug)], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + wp_output = white_player.stdout.readline() + wp_message = wp_output + while wp_output != '' and "Start requestLoop" not in wp_output: + wp_output = white_player.stdout.readline() + wp_message += wp_output + print("============ " + white_role_name + " message ============" + "\n" + wp_message), server_list = "" while (black_role_name not in server_list) or (white_role_name not in server_list): diff --git a/AlphaGo/player.py b/AlphaGo/player.py index b93c124..8d46ae5 100644 --- a/AlphaGo/player.py +++ b/AlphaGo/player.py @@ -24,16 +24,20 @@ if __name__ == '__main__': parser.add_argument("--game", type=str, default=False) args = parser.parse_args() - game = Game(name=args.game, role=args.role, checkpoint_path=eval(args.checkpoint_path), debug=eval(args.debug)) + if args.checkpoint_path == 'None': + args.checkpoint_path = None + game = Game(name=args.game, role=args.role, + checkpoint_path=args.checkpoint_path, + debug=eval(args.debug)) engine = GTPEngine(game_obj=game, name='tianshou', version=0) daemon = Pyro4.Daemon() # make a Pyro daemon ns = Pyro4.locateNS() # find the name server player = Player(role=args.role, engine=engine) - print "Init " + args.role + " player finished" + print("Init " + args.role + " player finished") uri = daemon.register(player) # register the greeting maker as a Pyro object - print "Start on name " + args.role + print("Start on name " + args.role) ns.register(args.role, uri) # register the object with a name in the name server - print "Start Request Loop " + str(uri) + print("Start requestLoop " + str(uri)) daemon.requestLoop() # start the event loop of the server to wait for calls