fixed watch, ensured flushing of everything

This commit is contained in:
Ari Brown 2024-07-25 08:51:47 -04:00
parent 94820beccc
commit 58f3d7074f

View file

@ -1,10 +1,19 @@
from fabric import Connection from fabric import Connection
import os import os
import sys
import threading import threading
import select import select
import tempfile import tempfile
import io import io
def flush_data(data, pipe, display=None):
pipe.write(data)
pipe.flush()
if display:
display.write(data)
display.flush()
# Bare machine, not necessarily associated with AWS # Bare machine, not necessarily associated with AWS
class Remote: class Remote:
def __init__(self, def __init__(self,
@ -77,8 +86,13 @@ class Remote:
channel.shutdown_write() channel.shutdown_write()
# read stdout/stderr to prevent read block hangs # read stdout/stderr to prevent read block hangs
out.write(channel.recv(len(channel.in_buffer))) flush_data(channel.recv(len(channel.in_buffer)),
err.write(channel.recv_stderr(len(channel.in_stderr_buffer))) out,
(watch and sys.stdout.buffer))
flush_data(channel.recv_stderr(len(channel.in_stderr_buffer)),
err,
(watch and sys.stderr.buffer))
timeout = 60 timeout = 60
@ -96,21 +110,16 @@ class Remote:
break break
for c in readq: for c in readq:
if c.recv_ready(): if c.recv_ready():
data = channel.recv(len(c.in_buffer)) flush_data(channel.recv(len(c.in_buffer)),
out.write(data) out,
out.flush() (watch and sys.stdout.buffer))
got_chunk = True got_chunk = True
if watch:
sys.stdout.write(data)
if c.recv_stderr_ready(): if c.recv_stderr_ready():
data = channel.recv_stderr(len(c.in_stderr_buffer)) flush_data(channel.recv_stderr(len(c.in_stderr_buffer)),
err.write(data) err,
err.flush() (watch and sys.stderr.buffer))
got_chunk = True got_chunk = True
if watch:
sys.stderr.write(data)
# for c # for c
""" """
@ -144,7 +153,6 @@ class Remote:
thread.start() thread.start()
if not disown: if not disown:
print("joining")
thread.join() thread.join()
return (open(out.name, "rb"), open(err.name, "rb"), thread) return (open(out.name, "rb"), open(err.name, "rb"), thread)