File fix-python3-and-unbuffered-io.patch of Package irqstat
commit 949d40b8d5c8bb78bb229d96c4b62122b66c4839
Author: Dario Faggioli <dfaggioli@suse.com>
Date: Tue Mar 23 16:01:15 2021 +0000
Workaround Python 3 not doing unbuffered IO for text files
On python3, running with -b cause this:
Traceback (most recent call last):
File "/usr/bin/irqstat", line 401, in <module>
sys.exit(main(sys.argv))
File "/usr/bin/irqstat", line 385, in main
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
File "/usr/lib64/python3.8/os.py", line 1023, in fdopen
return io.open(fd, *args, **kwargs)
ValueError: can't have unbuffered text I/O
That's because unbuffered IO can't be done any longer
(unless for binary IO).
Workaround that wrapping stdout in a stream that is always
flushed.
Signed-off-by: Dario Faggioli <dfaggioli@suse.com>
diff --git a/irqstat b/irqstat
index fe882f4..9183a5a 100755
--- a/irqstat
+++ b/irqstat
@@ -45,6 +45,17 @@ try:
except ImportError:
import _thread as thread
+class Unbuffered:
+ def __init__(self, stream):
+ self.stream = stream
+ def write(self, data):
+ self.stream.write(data)
+ self.stream.flush()
+ def writelines(self, datas):
+ self.stream.writelines(datas)
+ self.stream.flush()
+ def __getattr__(self, attr):
+ return getattr(self.stream, attr)
KEYEVENT = threading.Event()
@@ -382,7 +393,7 @@ def main(args):
# input thread
thread.start_new_thread(wait_for_input, tuple())
else:
- sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
+ sys.stdout = Unbuffered(sys.stdout)
try:
display_itop(options.batch, int(options.time), int(options.rows),