Skip to content

Commit b043875

Browse files
authored
Merge pull request #59 from Seedname/main
Improve slow Shell.live printing
2 parents 6f7f784 + 8eb622b commit b043875

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

src/cloudmesh/common/Shell.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,18 +1044,16 @@ def live(cls, command, cwd=None):
10441044
process = subprocess.Popen(
10451045
shlex.split(command), cwd=cwd, stdout=subprocess.PIPE
10461046
)
1047-
result = b""
1048-
while True:
1049-
output = process.stdout.read(1)
1050-
if output == b"" and process.poll() is not None:
1051-
break
1052-
if output:
1053-
result = result + output
1054-
sys.stdout.write(output.decode("utf-8"))
1055-
sys.stdout.flush()
1056-
rc = process.poll()
1057-
data = dotdict({"status": rc, "text": output.decode("utf-8")})
1058-
return data
1047+
1048+
output_lines = []
1049+
for line in iter(process.stdout.readline, b''):
1050+
sys.stdout.write(line.decode("utf-8"))
1051+
sys.stdout.flush()
1052+
output_lines.append(line)
1053+
1054+
rc = process.wait()
1055+
full_output = b"".join(output_lines).decode("utf-8")
1056+
return dotdict({"status": rc, "text": full_output})
10591057

10601058
@staticmethod
10611059
def calculate_disk_space(directory):

0 commit comments

Comments
 (0)