diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2019-06-11 16:25:04 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2019-07-10 08:14:51 +0000 |
commit | a6b0951da02188c62f6aea6b0ce3937ea5b092b7 (patch) | |
tree | 44edea43cb6220329cd08149c7e20faca9c2e302 | |
parent | d1a9a920812ee832d4e4c34a24e8d84c3c9665ca (diff) | |
download | buildstream-a6b0951da02188c62f6aea6b0ce3937ea5b092b7.tar.gz |
_frontend/cli.py: Exit with error if output streams are set to nonblocking
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) |