From ec6a33b736947611624112a4784afd184cf91787 Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Wed, 12 Jan 2022 01:57:20 +0200 Subject: [PATCH] [tune] fixes to allow tune/tests/test_commands.py to run on windows (#21342) tune does not run smoothly on Windows. This cleans up some blockers: - use cross-platform shutils.get_terminal_size instead of Popen(stty) - somehow Trainer.workers is None at the end of test_commands.py, so the cleanup command was erroring. The error was not fatal, but was printing in the logs. - if run locally, the log files are all written to the same location, so the rync-based syncing solution is not needed. This is the real fix for issue #20747 --- python/ray/tune/commands.py | 11 ++++------- rllib/agents/trainer.py | 5 +++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/python/ray/tune/commands.py b/python/ray/tune/commands.py index ed4970702..a3dc0820e 100644 --- a/python/ray/tune/commands.py +++ b/python/ray/tune/commands.py @@ -1,8 +1,9 @@ import click import logging -import os -import subprocess import operator +import os +import shutil +import subprocess from datetime import datetime import pandas as pd @@ -30,11 +31,7 @@ DEFAULT_PROJECT_INFO_KEYS = ( "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 36fd14620..9b04060d0 100644 --- a/rllib/agents/trainer.py +++ b/rllib/agents/trainer.py @@ -1848,8 +1848,9 @@ class Trainer(Trainable): @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()