Optimized ressources

This commit is contained in:
Kevin Veen-Birkenbach 2023-11-16 15:42:09 +01:00
parent 51006074b4
commit 9bd6de8043

View File

@ -4,22 +4,23 @@ import sys
import time import time
def run_command(command): def run_command(command):
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) process = None
output = [] try:
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = []
# Iterate over the output lines for line in iter(process.stdout.readline, b''):
for line in iter(process.stdout.readline, b''): decoded_line = line.decode()
decoded_line = line.decode() output.append(decoded_line)
output.append(decoded_line) sys.stdout.write(decoded_line)
sys.stdout.write(decoded_line)
process.stdout.close()
return_code = process.wait()
if return_code:
# Join the output list to create a single string
full_output = ''.join(output)
raise subprocess.CalledProcessError(return_code, command, output=full_output.encode())
return_code = process.wait()
if return_code:
full_output = ''.join(output)
raise subprocess.CalledProcessError(return_code, command, output=full_output.encode())
finally:
if process and process.stdout:
process.stdout.close()
def git_pull(directory): def git_pull(directory):
os.chdir(directory) os.chdir(directory)