When I tried to monitor the output of one python script from another none of the standard methods I could find were working. The things complicating this case is the first script need to continue running in parrallel and I need to monitor its output live. Also, the script does not have newlines - it just updates the current one.
Here's an MWE:
Script 1
import time
i=0
print("Starting")
while True:
time.sleep(1)
print("Running {: 5d}".format(i), end="\r")
i+=1
print()
Run from the shell, this outputs:
Starting
Running 3
(where the second line updates once per second)
And my initial unsuccessful attempts to monitor it:
a = subprocess.Popen(["python3", "noNewLine1.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True :
time.sleep(1)
# b = a.stdout.readline() # Doesn't work - hangs
# b = a.stdout.read(1) # also hangs
b = a.communicate(timeout=1) # Times out, no return
print(b)