From e11f91b0399a7379bbaf96728ebedc61cbc0b34e Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 13 Aug 2018 11:48:25 -0700 Subject: [PATCH] remove error message for Ctrl+C --- tests/rateLimiter.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/tests/rateLimiter.py b/tests/rateLimiter.py index 15222e01..d69523ca 100755 --- a/tests/rateLimiter.py +++ b/tests/rateLimiter.py @@ -23,20 +23,26 @@ rate *= 1.4 # compensation for excluding i/o time (experimentally determined) start = time.time() total_read = 0 -buf = " " -while len(buf): - now = time.time() - to_read = max(int(rate * (now - start) - total_read), 1) - max_buf_size = 1 * MB - to_read = min(to_read, max_buf_size) +sys.stderr.close() # remove error message, for Ctrl+C - read_start = time.time() - buf = sys.stdin.buffer.read(to_read) +try: + buf = " " + while len(buf): + now = time.time() + to_read = max(int(rate * (now - start) - total_read), 1) + max_buf_size = 1 * MB + to_read = min(to_read, max_buf_size) - write_start = read_end = time.time() - sys.stdout.buffer.write(buf) - write_end = time.time() + read_start = time.time() + buf = sys.stdin.buffer.read(to_read) - wait_time = max(read_end - read_start, write_end - write_start) - start += wait_time # exclude delay of the slowest - total_read += len(buf) + write_start = read_end = time.time() + sys.stdout.buffer.write(buf) + write_end = time.time() + + wait_time = max(read_end - read_start, write_end - write_start) + start += wait_time # exclude delay of the slowest + total_read += len(buf) + +except (KeyboardInterrupt, BrokenPipeError) as e: + pass