Skip to content

Instantly share code, notes, and snippets.

View meherhendi's full-sized avatar
🏠
Working from home

meherhendi

🏠
Working from home
View GitHub Profile
@meherhendi
meherhendi / non_blocking_subprocess_output.py
Last active January 31, 2024 16:56
Python non blocking subprocess output
# this function allows outputting the subprocess output to the console without blocking the execution of the program by
# assigning the printing function to a thread
def run_command(self, command):
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
def readstdout():
for line in p.stdout:
print(line.strip())