From 30a051ebe8e9b6ef8025dc8f84a746aa48b723fd Mon Sep 17 00:00:00 2001 From: mattip Date: Mon, 3 Jan 2022 15:50:00 +0200 Subject: [PATCH] fixes to allow tune/tests/test_commands.py to run on windows --- python/ray/tune/commands.py | 9 +++------ rllib/agents/trainer.py | 5 +++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/python/ray/tune/commands.py b/python/ray/tune/commands.py index ed4970702d9b..a3dc0820e11c 100644 --- a/python/ray/tune/commands.py +++ b/python/ray/tune/commands.py @@ -1,8 +1,9 @@ import click import logging +import operator import os +import shutil import subprocess -import operator from datetime import datetime import pandas as pd @@ -30,11 +31,7 @@ "last_updated", ) -try: - TERM_HEIGHT, TERM_WIDTH = subprocess.check_output(["stty", "size"]).split() - TERM_HEIGHT, TERM_WIDTH = int(TERM_HEIGHT), int(TERM_WIDTH) -except subprocess.CalledProcessError: - TERM_HEIGHT, TERM_WIDTH = 100, 100 +TERM_WIDTH, TERM_HEIGHT = shutil.get_terminal_size(fallback=(100, 100)) OPERATORS = { "<": operator.lt, diff --git a/rllib/agents/trainer.py b/rllib/agents/trainer.py index 36fd14620dc5..9b04060d014d 100644 --- a/rllib/agents/trainer.py +++ b/rllib/agents/trainer.py @@ -1848,8 +1848,9 @@ def log_result(self, result: ResultDict) -> None: @override(Trainable) def cleanup(self) -> None: # Stop all workers. - if hasattr(self, "workers"): - self.workers.stop() + workers = getattr(self, "workers", None) + if workers: + workers.stop() # Stop all optimizers. if hasattr(self, "optimizer") and self.optimizer: self.optimizer.stop()