diff options
-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) |