Skip to contentSkip to conversation

cooker.py: Catch when stdout doesn't have a file descriptor

PATCH New [email protected] 1 participant 1 message Aug 23, 2016 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 cooker.py: Catch when stdout doesn't have a file descriptor

From: Mariano Lopez <[email protected]>

Currently, there is a check to remove the TOSTOP attribute from a tty to avoid hangs. It assumes that sys.stdout will have a file descriptor and this is not always true, some IO classes will throw exceptions when trying to get its file descriptor.

This will add a check for such cases and avoid throwing an exception.

[YOCTO #10162]

---
 bitbake/lib/bb/cooker.py | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
bitbake/lib/bb/cooker.py +12 -9
index d1ab4aa..b7d7a7e 100644
@@ -30,7 +30,7 @@ import logging
 import multiprocessing
 import sre_constants
 import threading
-from io import StringIO
+from io import StringIO, UnsupportedOperation
 from contextlib import closing
 from functools import wraps
 from collections import defaultdict, namedtuple
@@ -230,14 +230,17 @@ class BBCooker:
             pass
 
         # TOSTOP must not be set or our children will hang when they output
-        fd = sys.stdout.fileno()
-        if os.isatty(fd):
-            import termios
-            tcattr = termios.tcgetattr(fd)
-            if tcattr[3] & termios.TOSTOP:
-                buildlog.info("The terminal had the TOSTOP bit set, clearing...")
-                tcattr[3] = tcattr[3] & ~termios.TOSTOP
-                termios.tcsetattr(fd, termios.TCSANOW, tcattr)
+        try:
+            fd = sys.stdout.fileno()
+            if os.isatty(fd):
+                import termios
+                tcattr = termios.tcgetattr(fd)
+                if tcattr[3] & termios.TOSTOP:
+                    buildlog.info("The terminal had the TOSTOP bit set, clearing...")
+                    tcattr[3] = tcattr[3] & ~termios.TOSTOP
+                    termios.tcsetattr(fd, termios.TCSANOW, tcattr)
+        except UnsupportedOperation:
+            pass
 
         self.command = bb.command.Command(self)
         self.state = state.initial
Signature · 1 line
2.6.6