Python's subprocess.Popen object hangs gathering child output when child process does not exit

前端 未结 4 1974
既然无缘
既然无缘 2021-01-07 06:16

When a process exits abnormally or not at all, I still want to be able to gather what output it may have generated up until that point.

The obvious solution to this

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-07 06:39

    I had the exact same problem. I ended up fixing the issue (after scouring Google and finding many related problems) by simply setting the following parameters when calling subprocess.Popen (or .call):

    stdout=None
    

    and

    stderr=None
    

    There are many problems with these functions but in my specific case I believe stdout was being filled up by the process I was calling and then resulting in a blocking condition. By setting these to None (opposed to something like subprocess.PIPE) I believe this is avoided.

    Hope this helps someone.

提交回复
热议问题