Skip to content

Instantly share code, notes, and snippets.

@samdphillips
Created January 22, 2015 03:20
Show Gist options
  • Save samdphillips/933fe99a3b54d5a0a002 to your computer and use it in GitHub Desktop.
Save samdphillips/933fe99a3b54d5a0a002 to your computer and use it in GitHub Desktop.
import sys
from datetime import datetime, timedelta
from syslog import syslog
five_sec = timedelta(seconds=5)
last = datetime.now()
count = 0
while True:
try:
data = sys.stdin.readline()
now = datetime.now()
count += 1
if last + five_sec <= now:
print '%s count=%d' % (now, count)
syslog('[counter] count=%d' % count)
count = 0
last = now
except KeyboardInterrupt:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment