簡體   English   中英

python subprocess子線程不退出?

[英]python subprocess sub thread does not exit?

以下代碼很奇怪:

def exec_shell(args, pipe = True):
    pre_fun = None
    if pipe == True:
        pre_fun = lambda: signal.signal(signal.SIGPIPE, signal.SIG_DFL)

    process = subprocess.Popen(args, stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        preexec_fn = pre_fun)
    (out, err) = process.communicate() 

當我執行復雜的shell腳本時,如果我將管道設置為true:err將為:如果我將管道設置為false,則在運行2個線程時退出了一個線程,err將是:管道破裂

誰能幫我 ? 謝謝

您可以使用簡單的os.popen()函數。 我程序中的示例:

import os
manifest = os.popen("aapt dump badging " + apk).read() #running command
for info in manifest.splitlines():
    ...  # extracting values

此外,子進程模塊有一個錯誤:如果在subprocess.Popen()中指定了非ASCII路徑,則會發生錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM