Created
April 25, 2018 08:00
-
-
Save hyperair/fbc43dce3f54c3865889af4158efdeee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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