2013-12-08 15 views

回答

2

使用select.select。 (在Windows中,你只能用插座):

import select 

... 

r, _, _ = select.select([fd], [], [], 0) 
if r: 
    data = os.read(fd, 1024) 
+0

該工作在pty環境下嗎?我正在用proc_open從另一個進程(不是python)讀取python程序的標準輸出(正在運行:pty.spawn(/ bin/sh))。上述代碼仍然存在懸而未決的問題。如果有輸出,它會讀取它,如果沒有,它會掛起和方式。 – OBV

+0

@OBV,'select.select'將立即以'timeout'(第四個參數)返回爲0. – falsetru

+0

是指select.select([fd] ...寧可? – OBV