Is there a way to poll a file handle returned from subprocess.Popen?

后端 未结 2 436
一生所求
一生所求 2021-02-04 20:46

Say I write this:

from subprocessing import Popen, STDOUT, PIPE
p = Popen([\"myproc\"], stderr=STDOUT, stdout=PIPE)

Now if I do



        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-04 21:31

    Use the select module in Python's standard library, see http://docs.python.org/library/select.html . select.select([p.stdout.fileno()], [], [], 0) immediately returns a tuple whose items are three lists: the first one is going to be non-empty if there's something to read on that file descriptor.

提交回复
热议问题