Skip to content

Commit 0cf0765

Browse files
authored
Fix output for parallel down (skypilot-org#666)
* Fix output for parallel down * format * linting * fix import
1 parent f45b619 commit 0cf0765

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

sky/cli.py

+24-18
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import yaml
4040

4141
import click
42+
import colorama
4243
import pendulum
4344
from rich import progress as rich_progress
4445

@@ -1301,13 +1302,12 @@ def _terminate_or_stop_clusters(names: Tuple[str],
13011302
abort=True,
13021303
show_default=True)
13031304

1304-
progress = rich_progress.Progress(transient=True)
13051305
operation = 'Terminating' if terminate else 'Stopping'
13061306
plural = 's' if len(to_down) > 1 else ''
1307+
progress = rich_progress.Progress(transient=True)
13071308
task = progress.add_task(
13081309
f'[bold cyan]{operation} {len(to_down)} cluster{plural}[/]',
13091310
total=len(to_down))
1310-
progress.start()
13111311

13121312
def _terminate_or_stop(record):
13131313
name = record['name']
@@ -1317,30 +1317,36 @@ def _terminate_or_stop(record):
13171317
handle.launched_resources.use_spot and not terminate):
13181318
# Disable spot instances to be stopped.
13191319
# TODO(suquark): enable GCP+spot to be stopped in the future.
1320-
progress.stop()
1321-
click.secho(
1322-
f'Stopping cluster {name}... skipped, because spot instances '
1323-
'may lose attached volumes. ',
1324-
fg='green')
1325-
click.echo(' To terminate the cluster, run: ', nl=False)
1326-
click.secho(f'sky down {name}', bold=True)
1320+
message = (
1321+
f'{colorama.Fore.GREEN}Stopping cluster {name}... skipped.'
1322+
f'{colorama.Style.RESET_ALL}\n'
1323+
' The spot instances may lose attached volumes.\n'
1324+
' To terminate the cluster, run: '
1325+
f'{colorama.Style.BRIGHT}sky down {name}'
1326+
f'{colorama.Style.RESET_ALL}')
13271327
else:
13281328
success = backend.teardown(handle, terminate=terminate, purge=purge)
1329-
progress.stop()
13301329
if success:
1331-
click.secho(f'{operation} cluster {name}...done.', fg='green')
1330+
message = (
1331+
f'{colorama.Fore.GREEN}{operation} cluster {name}...done.'
1332+
f'{colorama.Style.RESET_ALL}')
13321333
if not terminate:
1333-
click.echo(' To restart the cluster, run: ', nl=False)
1334-
click.secho(f'sky start {name}', bold=True)
1334+
message += ('\n To restart the cluster, run: '
1335+
f'{colorama.Style.BRIGHT}sky start {name}'
1336+
f'{colorama.Style.RESET_ALL}')
13351337
else:
1336-
click.secho(
1337-
f'{operation} cluster {name}...failed. '
1338-
'Please check the logs and try again.',
1339-
fg='red')
1338+
message = (
1339+
f'{colorama.Fore.RED}{operation} cluster {name}...failed. '
1340+
'Please check the logs and try again.'
1341+
f'{colorama.Style.RESET_ALL}')
1342+
progress.stop()
1343+
click.echo(message)
13401344
progress.update(task, advance=1)
13411345
progress.start()
13421346

1343-
backend_utils.run_in_parallel(_terminate_or_stop, to_down)
1347+
with progress:
1348+
backend_utils.run_in_parallel(_terminate_or_stop, to_down)
1349+
progress.live.transient = False
13441350

13451351

13461352
@_interactive_node_cli_command

0 commit comments

Comments
 (0)