pipe large amount of data to stdin while using subprocess.Popen

后端 未结 10 640
花落未央
花落未央 2020-12-08 11:08

I\'m kind of struggling to understand what is the python way of solving this simple problem.

My problem is quite simple. If you use the follwing code it will hang. T

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 11:48

    For this kind of thing, the shell works a lot better than subprocess.

    Write very simple Python apps which read from sys.stdin and write to sys.stdout.

    Connect the simple apps together using a shell pipeline.

    If you want, start the pipeline using subprocess or simply write a one-line shell script.

    python part1.py | python part2.py
    

    This is very, very efficient. It's also portable to all Linux (and Windows) as long as you keep it very simple.

提交回复
热议问题