diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2019-06-11 16:25:04 +0900 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-07-04 13:44:57 +0000 |
commit | 41e02b3220fd90638e8dff0630f6ad296fc62a22 (patch) | |
tree | b692164485f15b8ba99a0bf3990a197e9c7f7370 | |
parent | a80adc03bfa6cd2ba7a7fe3981f00556e5e1f5da (diff) | |
download | buildstream-tristan/exit-on-nonblock-terminal.tar.gz |
_frontend/cli.py: Exit with error if output streams are set to nonblockingtristan/exit-on-nonblock-terminal
This is better than raising a stack trace later on when logging gets
intense with a BlockingIOError.
This fixes #929
-rw-r--r-- | src/buildstream/_frontend/cli.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py index 9a753f77a..e9d67ca87 100644 --- a/src/buildstream/_frontend/cli.py +++ b/src/buildstream/_frontend/cli.py @@ -3,6 +3,7 @@ import sys from contextlib import ExitStack from functools import partial from tempfile import TemporaryDirectory +import fcntl import click from .. import _yaml @@ -191,6 +192,17 @@ def override_main(self, args=None, prog_name=None, complete_var=None, # Regular client return for test cases return + # Check output file descriptor at earliest opportunity, to + # provide a reasonable error message instead of a stack trace + # in the case that it is blocking + for stream in (sys.stdout, sys.stderr): + fileno = stream.fileno() + flags = fcntl.fcntl(fileno, fcntl.F_GETFL) + if flags & os.O_NONBLOCK: + click.echo("{} is currently set to O_NONBLOCK, try opening a new shell" + .format(stream.name), err=True) + sys.exit(-1) + original_main(self, args=args, prog_name=prog_name, complete_var=None, standalone_mode=standalone_mode, **extra) |