python program is started with
/usr/bin/python2.6 test.py or ... python2.7 test.py
test.py:
- Code: Select all
import fcntl, os, subprocess, time
p = subprocess.Popen([pythonPath, '/xxx/yyy/pgm.py'], stdout = subprocess.PIPE, shell = False)
flags = fcntl.fcntl(p.stdout, fcntl.F_GETFL) # get current p.stdout flags
fcntl.fcntl(p.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
while True:
try:
time.sleep(1)
print "hello"
xx = os.read(p.stdout.fileno(), 1024)
if len(xx) > 5: print xx
except OSError:
time.sleep(5)
(*) pgm.py:
- Code: Select all
import time
while true:
print "abc"
sys.stdout.flush()
time.sleep(3)
any advice?
thx
Karl