Skip to content

Instantly share code, notes, and snippets.

@mbreese
Created March 14, 2018 10:30
Show Gist options
  • Save mbreese/00048f920718c53ce4ff5975f9c81a9d to your computer and use it in GitHub Desktop.
Save mbreese/00048f920718c53ce4ff5975f9c81a9d to your computer and use it in GitHub Desktop.
Sampling program to read write every X lines to stderr, otherwise, just read from stdin and write to stdout (useful for monitoring stream progress)
#!/usr/bin/env python
import sys
import datetime
rate = 100000
if len(sys.argv) > 1:
rate = int(sys.argv[1])
i = 0
for line in sys.stdin:
i += 1
if i > rate:
sys.stderr.write('\n%s\n' % datetime.datetime.now())
sys.stderr.write(line)
i = 0
sys.stdout.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment