seigot / tetris

A Tetris Game for programming education in Japanese
MIT License
30 stars 107 forks source link

fix stdout setting in start.py #115

Closed EndoNrak closed 1 year ago

EndoNrak commented 1 year ago

https://github.com/seigot/tetris/pull/112#issuecomment-1546937288

【症状】 テトリスの標準出力が表示されない

【原因】 capture_output=trueにしていたため start.pyから呼び出す子プロセスの標準出力をその場で表示できていなかった

【対処方法】 subprocess.run()のオプションを変更。エラーのみを受け取れるようにstderr=PIPEに変更

EndoNrak commented 1 year ago

エラーは想定通りにキャッチできている

$ python start.py -m predict --predict_weight aaa.pt
game_level: 1
game_time: 180
RANDOM_SEED: 0
IS_MODE :predict
IS_NEXTSHAPEMODE :default
OBSTACLE_HEIGHT: 0
OBSTACLE_PROBABILITY: 0
USER_NAME: window_sample
SHAPE_LIST_MAX: 6
BLOCK_NUM_MAX: 180
RESULT_LOG_JSON: result.json
TRAIN_YAML: config/default.yaml
PREDICT_WEIGHT: aaa.pt
ART_CONFIG: default.json
Python 3.10.0
CompletedProcess(args='python --version', returncode=0, stderr='')
model name: DQN
tetris_fill_reward: 0.0001
tetris_fill_height: 11
height_line_reward: 3
hole_top_limit_reward: 1e-05
hole_top_limit: 1
hole_top_limit_height: 5
left_side_height_penalty: 1e-05
over3_diff_penalty: 0.01
bumpiness_left_side_relax: 1
max_height_relax: 14
Load aaa.pt...
Traceback (most recent call last):
  File "C:\Users\eva_s\projects\tetris\start.py", line 201, in <module>
    start()
  File "C:\Users\eva_s\projects\tetris\start.py", line 192, in start
    raise Exception(ret.stderr)
Exception: Traceback (most recent call last):
  File "C:\Users\eva_s\projects\tetris\game_manager\game_manager.py", line 335, in timerEvent
    self.nextMove = BLOCK_CONTROLLER_TRAIN.GetNextMove(nextMove, GameStatus,yaml_file=self.train_yaml,weight=self.predict_weight)   
  File "C:\Users\eva_s\projects\tetris\game_manager\machine_learning\block_controller_train.py", line 1428, in GetNextMove
    self.set_parameter(yaml_file=yaml_file,predict_weight=weight)
  File "C:\Users\eva_s\projects\tetris\game_manager\machine_learning\block_controller_train.py", line 326, in set_parameter
    self.model = torch.load(predict_weight)
  File "C:\Users\eva_s\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\serialization.py", line 771, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "C:\Users\eva_s\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\serialization.py", line 270, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "C:\Users\eva_s\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\serialization.py", line 251, in __init__     
    super(_open_file, self).__init__(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: 'aaa.pt'
seigot commented 1 year ago

ありがとうございます!