I have some python code which I would like to open as a subprocess. I have tried threading the process through subprocess.Popen() and also through asyncio from another Python script. I know that the addition of time.sleep() is preventing the process output from being read as the program produces output, but a time consuming large loop has the same effect. Interestingly enough, anything I try works from Eclipse with PyDev, but if I run my program from the shell it only outputs when the program is finally finished running. I need to be able to read output as the program outputs to stdout as it progresses. Any help would be greatly appreciated.
# would like to call this python script as a subprocess from another program.
import time
import sys
for j in range( 50000000000 ):
print("blah") # if this is removed asynchronous reading occurs just fine
time.sleep(1)
#for k in range( 10000000 ): # this would also cause output to wait until program is complete
# b=2
print("\n"*2)