我試圖從管道讀取線路並處理它們,但我正在做一些愚蠢的事情,我無法弄清楚什麼。生產者將要無限期地保持生產線,像這樣:Python - 簡單的讀管道從管道
producer.py
import time
while True:
print 'Data'
time.sleep(1)
消費者只需要定期檢查線路:
consumer.py
import sys, time
while True:
line = sys.stdin.readline()
if line:
print 'Got data:', line
else:
time.sleep(1)
當我在Windows shell中以python producer.py | python consumer.py
的形式運行它時,它只是永遠睡眠(似乎永遠不會獲取數據?)似乎可能問題在於生成ucer永遠不會終止,因爲如果我發送有限數量的數據,那麼它工作正常。
如何獲取要接收的數據並顯示給消費者?在實際應用中,製作者是我無法控制的C++程序。
你讀過這個問題的最後一句話嗎? – jwg 2014-12-18 15:10:53