Skip to content

Instantly share code, notes, and snippets.

@romuald
Created December 3, 2014 17:22
Show Gist options
  • Save romuald/ad97f4660790faaea486 to your computer and use it in GitHub Desktop.
Save romuald/ad97f4660790faaea486 to your computer and use it in GitHub Desktop.
pong ping
# pong.py
import sys
from time import time, sleep
while True:
print time()
sys.stdout.flush()
sleep(1)
# ping.py
import sys
from time import time
from datetime import datetime
last = time()
try:
while True:
line = sys.stdin.readline().strip()
now = time()
if not line:
break
ts = datetime.fromtimestamp(now).strftime('%Y-%m-%d %H:%M:%S')
deltahere = now - last
delta = abs(now - float(line))
if deltahere > 1.2:
print "%s: +%.02f (delta %.02f)" % (ts, deltahere, delta)
last = now
except KeyboardInterrupt:
pass
@romuald
Copy link
Author

romuald commented Dec 3, 2014

Usage: ssh user@host pong.py | ping.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment