Skip to content

Instantly share code, notes, and snippets.

@no1xsyzy
Created January 19, 2021 04:39
Show Gist options
  • Save no1xsyzy/53f4f127f30a4c6b478b8e2a899e0b5a to your computer and use it in GitHub Desktop.
Save no1xsyzy/53f4f127f30a4c6b478b8e2a899e0b5a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""Usage: ... | pipe-throttle.py [NUMBER]
Read and write 1 byte, then sleep for NUMBER seconds.
Keep doing this until cannot read anything.
If NUMBER is not provided, sleep for 1 second instead.
-h, --help display this help and exit
"""
import sys
import time
if sys.argv[1:]:
if sys.argv[1] in ("--help", "-h"):
print(__doc__)
sys.exit(0)
sleep_sec = float(sys.argv[1])
else:
sleep_sec = 1
while True:
if inp := sys.stdin.read(1):
sys.stdout.write(inp)
sys.stdout.flush()
time.sleep(sleep_sec)
else:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment