3 # ################################################################
4 # Copyright (c) Meta Platforms, Inc. and affiliates.
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 # You may select, at your option, one of the above-listed licenses.
11 # ##########################################################################
13 # Rate limiter, replacement for pv
14 # this rate limiter does not "catch up" after a blocking period
16 # - only accepts limit speed in MB/s
22 rate = float(sys.argv[1]) * MB
26 # sys.stderr.close() # remove error message, for Ctrl+C
32 to_read = max(int(rate * (now - start)), 1)
34 to_read = min(to_read, max_buf_size)
37 buf = sys.stdin.buffer.read(to_read)
38 sys.stdout.buffer.write(buf)
40 except (KeyboardInterrupt, BrokenPipeError) as e: