Skip to content

Commit

Permalink
cli: check for closed stdout/stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrowla committed Apr 5, 2022
1 parent fa7b371 commit ee0a47f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion dvc/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This module provides an entrypoint to the dvc cli and parsing utils."""

import logging
import sys

# Workaround for CPython bug. See [1] and [2] for more info.
# [1] https://github.com/aws/aws-cli/blob/1.16.277/awscli/clidriver.py#L55
Expand Down Expand Up @@ -48,6 +49,16 @@ def main(argv=None): # noqa: C901
from dvc.exceptions import DvcException, NotDvcRepoError
from dvc.logger import FOOTER, disable_other_loggers

# NOTE: stderr/stdout may be closed if we are running from dvc.daemon.
# On Linux we directly call cli.main after double forking and closing
# the copied parent's standard file descriptors. If we make any logging
# calls in this state it will cause an exception due to writing to a closed
# file descriptor.
if sys.stderr.closed: # pylint: disable=using-constant-test
logging.disable()
elif sys.stdout.closed: # pylint: disable=using-constant-test
logging.disable(logging.INFO)

args = None
disable_other_loggers()

Expand All @@ -68,7 +79,7 @@ def main(argv=None): # noqa: C901

logger.trace(args)

if not args.quiet:
if not sys.stdout.closed and not args.quiet:
from dvc.ui import ui

ui.enable()
Expand Down

0 comments on commit ee0a47f

Please sign in to comment.