<tfoot id='S94F1'></tfoot>

<small id='S94F1'></small><noframes id='S94F1'>

      1. <legend id='S94F1'><style id='S94F1'><dir id='S94F1'><q id='S94F1'></q></dir></style></legend>
          <bdo id='S94F1'></bdo><ul id='S94F1'></ul>
      2. <i id='S94F1'><tr id='S94F1'><dt id='S94F1'><q id='S94F1'><span id='S94F1'><b id='S94F1'><form id='S94F1'><ins id='S94F1'></ins><ul id='S94F1'></ul><sub id='S94F1'></sub></form><legend id='S94F1'></legend><bdo id='S94F1'><pre id='S94F1'><center id='S94F1'></center></pre></bdo></b><th id='S94F1'></th></span></q></dt></tr></i><div id='S94F1'><tfoot id='S94F1'></tfoot><dl id='S94F1'><fieldset id='S94F1'></fieldset></dl></div>
      3. 使用 subprocess.Popen 的非常大的输入和管道

        时间:2023-07-21

        <small id='wpvxN'></small><noframes id='wpvxN'>

      4. <tfoot id='wpvxN'></tfoot>
          <tbody id='wpvxN'></tbody>
            <bdo id='wpvxN'></bdo><ul id='wpvxN'></ul>

              <i id='wpvxN'><tr id='wpvxN'><dt id='wpvxN'><q id='wpvxN'><span id='wpvxN'><b id='wpvxN'><form id='wpvxN'><ins id='wpvxN'></ins><ul id='wpvxN'></ul><sub id='wpvxN'></sub></form><legend id='wpvxN'></legend><bdo id='wpvxN'><pre id='wpvxN'><center id='wpvxN'></center></pre></bdo></b><th id='wpvxN'></th></span></q></dt></tr></i><div id='wpvxN'><tfoot id='wpvxN'></tfoot><dl id='wpvxN'><fieldset id='wpvxN'></fieldset></dl></div>
              <legend id='wpvxN'><style id='wpvxN'><dir id='wpvxN'><q id='wpvxN'></q></dir></style></legend>

                1. 本文介绍了使用 subprocess.Popen 的非常大的输入和管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个很简单的问题.我有一个大文件,它经过三个步骤,一个使用外部程序的解码步骤,在 python 中的一些处理,然后使用另一个外部程序重新编码.我一直在使用 subprocess.Popen() 尝试在 python 中执行此操作,而不是形成 unix 管道.但是,所有数据都缓冲到内存中.有没有一种 Python 的方式来完成这项任务,或者我最好退回到一个简单的 Python 脚本,该脚本从标准输入读取并在任一侧使用 unix 管道写入标准输出?

                  I have pretty simple problem. I have a large file that goes through three steps, a decoding step using an external program, some processing in python, and then recoding using another external program. I have been using subprocess.Popen() to try to do this in python rather than forming unix pipes. However, all the data are buffered to memory. Is there a pythonic way of doing this task, or am I best dropping back to a simple python script that reads from stdin and writes to stdout with unix pipes on either side?

                  import os, sys, subprocess
                  
                  def main(infile,reflist):
                      print infile,reflist
                      samtoolsin = subprocess.Popen(["samtools","view",infile],
                                                    stdout=subprocess.PIPE,bufsize=1)
                      samtoolsout = subprocess.Popen(["samtools","import",reflist,"-",
                                                      infile+".tmp"],stdin=subprocess.PIPE,bufsize=1)
                      for line in samtoolsin.stdout.read():
                          if(line.startswith("@")):
                              samtoolsout.stdin.write(line)
                          else:
                              linesplit = line.split("	")
                              if(linesplit[10]=="*"):
                                  linesplit[9]="*"
                              samtoolsout.stdin.write("	".join(linesplit))
                  

                  推荐答案

                  Popen 有一个 bufsize 参数,它将限制内存中缓冲区的大小.如果您根本不希望内存中的文件,您可以将文件对象作为 stdinstdout 参数传递.来自 子进程文档:

                  Popen has a bufsize parameter that will limit the size of the buffer in memory. If you don't want the files in memory at all, you can pass file objects as the stdin and stdout parameters. From the subprocess docs:

                  bufsize,如果给定,与内置 open() 函数的相应参数具有相同的含义:0 表示无缓冲,1 表示行缓冲,任何其他正值表示使用(大约)该大小的缓冲区.负 bufsize 表示使用系统默认值,通常表示完全缓冲.bufsize 的默认值为 0(无缓冲).

                  bufsize, if given, has the same meaning as the corresponding argument to the built-in open() function: 0 means unbuffered, 1 means line buffered, any other positive value means use a buffer of (approximately) that size. A negative bufsize means to use the system default, which usually means fully buffered. The default value for bufsize is 0 (unbuffered).

                  这篇关于使用 subprocess.Popen 的非常大的输入和管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:运行 git 命令时如何获取子进程标准输出? 下一篇:Python3子进程输出

                  相关文章

                    <i id='xO9Xa'><tr id='xO9Xa'><dt id='xO9Xa'><q id='xO9Xa'><span id='xO9Xa'><b id='xO9Xa'><form id='xO9Xa'><ins id='xO9Xa'></ins><ul id='xO9Xa'></ul><sub id='xO9Xa'></sub></form><legend id='xO9Xa'></legend><bdo id='xO9Xa'><pre id='xO9Xa'><center id='xO9Xa'></center></pre></bdo></b><th id='xO9Xa'></th></span></q></dt></tr></i><div id='xO9Xa'><tfoot id='xO9Xa'></tfoot><dl id='xO9Xa'><fieldset id='xO9Xa'></fieldset></dl></div>

                      <bdo id='xO9Xa'></bdo><ul id='xO9Xa'></ul>

                      <legend id='xO9Xa'><style id='xO9Xa'><dir id='xO9Xa'><q id='xO9Xa'></q></dir></style></legend><tfoot id='xO9Xa'></tfoot>
                    1. <small id='xO9Xa'></small><noframes id='xO9Xa'>