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:17:50 +0000 |
commit | acf4962f0c010a0344e252ffacce741118a844a1 (patch) | |
tree | 2b5cd80625cba32989a84af0336e1949c7ca42fb /buildstream | |
parent | d6bc33fe23e169221130083e5ef3ccdc6e29aef6 (diff) | |
download | buildstream-acf4962f0c010a0344e252ffacce741118a844a1.tar.gz |
_frontend/cli.py: Exit with error if output streams are set to nonblockingtristan/exit-on-nonblock-terminal-1.2
This is better than raising a stack trace later on when logging gets
intense with a BlockingIOError.
This fixes #929
Diffstat (limited to 'buildstream')
-rw-r--r-- | buildstream/_frontend/cli.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py index 20624e2ac..cf143f1c8 100644 --- a/buildstream/_frontend/cli.py +++ b/buildstream/_frontend/cli.py @@ -1,5 +1,6 @@ import os import sys +import fcntl import click from .. import _yaml @@ -158,6 +159,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) |