Skip to content

cli/colors: crash when importing if sys.stdout is closed #418

@d4l3k

Description

@d4l3k

🐛 Bug

Sometimes sys.stdout is closed and isatty() throws an error at https://github.com/pytorch/torchx/blob/main/torchx/cli/colors.py#L11

Switching to a variant that checks if it's closed should work:

not sys.stdout.closed and sys.stdout.isatty()

Module (check all that applies):

  • torchx.spec
  • torchx.component
  • torchx.apps
  • torchx.runtime
  • torchx.cli
  • torchx.schedulers
  • torchx.pipelines
  • torchx.aws
  • torchx.examples
  • other

To Reproduce

I'm not sure how to repro this externally other than explicitly closing sys.stdout

I/O operation on closed file
Stack trace:
...
from torchx.cli.cmd_log import get_logs
File: <"/mnt/xarfuse/uid-27156/4adc7caa-seed-nspid4026533510_cgpid2017229-ns-4026533507/torchx/cli/cmd_log.py">, line 20, in <module>
from torchx.cli.colors import GREEN, ENDC
File: <"/mnt/xarfuse/uid-27156/4adc7caa-seed-nspid4026533510_cgpid2017229-ns-4026533507/torchx/cli/colors.py">, line 11, in <module>
if sys.stdout.isatty():

Expected behavior

Doesn't crash

Environment

  • torchx version (e.g. 0.1.0rc1): main
  • Python version:
  • OS (e.g., Linux):
  • How you installed torchx (conda, pip, source, docker):
  • Docker image and tag (if using docker):
  • Git commit (if installed from source):
  • Execution environment (on-prem, AWS, GCP, Azure etc):
  • Any other relevant information:

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcliRelated to the CLI

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions