I think that you may create a child process using the subprocess
module, but you may want to do something like monitoring the log of that, so make a note.
The number is output as standard every 0.5 seconds.
child.py
import time
import sys
i = 0
while True:
print i
sys.stdout.flush()
i += 1
time.sleep(0.5)
The point is to flush ()
and expel the data stored in the buffer.
Whenever a child outputs, it will be output.
parent.py
import subprocess
proc = subprocess.Popen(['python','child.py'],stdout=subprocess.PIPE)
print "ready"
for line in iter(proc.stdout.readline,''):
print line
ready
1
2
3
4
5
(The following is omitted)
The part to be read from the child process seems to be various if you create a thread and read it asynchronously and queue the data.
Recommended Posts