简体   繁体   English

Python 脚本调用正确完成的外部程序,但仍作为正在运行的进程?

[英]Python script calls external program which comepletes correctly, yet remains as a running process?

I've got a python script that calls this function multiple different times using different programs:我有一个 python 脚本,它使用不同的程序多次调用这个函数:

def mediaprocess(action):
    try:
        p = subprocess.Popen(action,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
        output, err = p.communicate()
        temp.write(str(p.returncode))
    except CalledProcessError as e:
        cleanandexit(1,e.message)
    finally:
        p.kill()
    return str(output)

However after my script completes successfully, one call I make to mkvmerge remains if I do ps aux, I get many, many of these processes (see below) still on the list?然而,在我的脚本成功完成后,如果我执行 ps aux,我对 mkvmerge 的一个调用仍然存在,我得到很多很多这些进程(见下文)仍然在列表中?

plex       28571  0.0  0.0  12304  2784 ?        SNs  18:04   0:00 /usr/local/bin/mkvmerge -q -o /PlexStuff/PostProcess/newmkvfile.mkv /PlexStuff/PostProcess/tempvideo.mkv --language 0:eng /PlexStuff/PostProcess/Unsolved Mysteries (1987) - 2020-09-26 17 00 00 - Unsolved Mysteries.srt

I added the p.kill() to my script and it didn't make any difference.我将 p.kill() 添加到我的脚本中,它没有任何区别。 On the command line I have to do kill -9 to get rid of these old processes... but this shouldn't be necessary, all of the other programs I'm running ( mediainfo, handbrake, ffmpeg) all work perfectly.在命令行上,我必须执行 kill -9 才能摆脱这些旧进程……但这应该不是必需的,我正在运行的所有其他程序(mediainfo、handbrake、ffmpeg)都可以完美运行。

What gives?是什么赋予了?

经过更多的混乱和阅读之后,我发现 p.terminate() 在 p.kill() 没有工作时起作用,所以我将使用它,仍然不确定该程序行为的原因,但这有效目前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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