2
我正在测试与子进程的通信。我必须启动一个服务器,定期发送数据。最终目标是获取气象数据和绘图服务器的过程。采样率的顺序或分钟....我写了这两段代码,以了解python的基本知识,但我甚至无法使他们的工作。 同步性不是问题。将数据连续发送到子进程
主处理
import sys, time
from subprocess import Popen, PIPE
print 'starting'
proc = Popen (['python.exe',
'C:\Documents and Settings\Administrator\Desktop\sub.py'],
stdin = PIPE, stdout = PIPE)
print 'launched'
w = 0
while True:
w += 1
time.sleep (2)
print 'writing', w
proc.stdin.write (repr(w))
proc.stdin.flush()
print proc.stdout.read()
子过程:
import sys, time
print 'reading'
v = 0
while True:
v = sys.stdin.read()
sys.stdout.write('ACK')
sys.stdout.flush()
time.sleep (4)
主要过程被阻断,显然子不读取-发送ACK。 我在哪里错了?感谢
太棒了!有用。这是我在论坛上的第一篇文章,非常有用。谢谢 – user2202117 2013-03-23 16:50:41
是的,SO是最好的。当你找到有帮助的答案时,请随时注意或接受它。 – shx2 2013-03-23 17:00:24