Skip to content

Instantly share code, notes, and snippets.

@hyperair
Created April 25, 2018 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyperair/fbc43dce3f54c3865889af4158efdeee to your computer and use it in GitHub Desktop.
Save hyperair/fbc43dce3f54c3865889af4158efdeee to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import subprocess
import os
import sys
import time
ssh_host = sys.argv[1]
stdin_pipe = os.pipe()
stdout_pipe = os.pipe()
proc = subprocess.Popen(['ssh', ssh_host, 'cat'],
stdin=stdin_pipe[0], stdout=stdout_pipe[1])
os.close(stdin_pipe[0])
os.close(stdout_pipe[1])
try:
while True:
start = time.time()
os.write(stdin_pipe[1], b'z')
assert os.read(stdout_pipe[0], 1) == b'z'
end = time.time()
print('{0:.3f} ms'.format((end - start) * 1000))
time.sleep(1)
except KeyboardInterrupt:
pass
finally:
os.close(stdin_pipe[1])
os.close(stdout_pipe[0])
proc.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment