2013-12-08 14 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