From fa3bfc3a66cc081b0aacacc2124a7666c73c6288 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 7 Jan 2013 03:59:08 +0100 Subject: [PATCH] test: put tty in blocking mode after test Tests can leave the tty in non-blocking mode. If the test runner tries to print to stdout/stderr after that and the tty buffer is full, it'll die with a EAGAIN OSError. Ergo, put the tty back in blocking mode before proceeding. --- tools/test.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/test.py b/tools/test.py index e94ad24..29e850d 100755 --- a/tools/test.py +++ b/tools/test.py @@ -400,10 +400,20 @@ class TestCase(object): def Run(self): self.BeforeRun() + try: result = self.RunCommand(self.GetCommand()) finally: - self.AfterRun(result) + # Tests can leave the tty in non-blocking mode. If the test runner + # tries to print to stdout/stderr after that and the tty buffer is + # full, it'll die with a EAGAIN OSError. Ergo, put the tty back in + # blocking mode before proceeding. + if sys.platform != 'win32': + from fcntl import fcntl, F_GETFL, F_SETFL + from os import O_NONBLOCK + for fd in 0,1,2: fcntl(fd, F_SETFL, ~O_NONBLOCK & fcntl(fd, F_GETFL)) + + self.AfterRun(result) return result def Cleanup(self): -- 2.7.4