3 # ################################################################
4 # Copyright (c) 2018-present, Facebook, Inc.
7 # This source code is licensed under both the BSD-style license (found in the
8 # LICENSE file in the root directory of this source tree) and the GPLv2 (found
9 # in the COPYING file in the root directory of this source tree).
10 # ##########################################################################
12 # Rate limiter, replacement for pv
13 # this rate limiter does not "catch up" after a blocking period
15 # - only accepts limit speed in MB/s
21 rate = float(sys.argv[1]) * MB
25 # sys.stderr.close() # remove error message, for Ctrl+C
31 to_read = max(int(rate * (now - start)), 1)
33 to_read = min(to_read, max_buf_size)
36 buf = sys.stdin.buffer.read(to_read)
37 sys.stdout.buffer.write(buf)
39 except (KeyboardInterrupt, BrokenPipeError) as e: