简体   繁体   中英

python subprocess sub thread does not exit?

the following code is strange:

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() 

when i execute a complicate shell script, if i set the pipe is true: the err will be : A thread exited while 2 threads were running if i set pipe false the err will be : broken pipe

who can help me ? thanks

You can use simplier os.popen() function. Example from my program:

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

Also, subprocess module has a bug: if in subprocess.Popen() you specify non-ascii path, then error will occur.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM