Killing shell = True进程导致ResourceWarning:子进程仍在运行

时间:2018-09-24 09:27:26

标签: python subprocess

遵循How to terminate a python subprocess launched with shell=True的建议

我有一个从以下内容开始的过程

process = subprocess.Popen(my_cmd, shell=True, executable='/bin/bash', preexec_fn=os.setsid)

my_cmd的格式为some_cmd_that_periodically_outputs_to_stdout | grep "some_fancy_regex" > some_output_file.txt

我用以下方法杀死进程

os.killpg(os.getpgid(process.pid), signal.SIGKILL)

杀死后,我得到以下警告

ResourceWarning: subprocess XXX is still running

我为什么收到此警告?

1 个答案:

答案 0 :(得分:2)

您没有public class Main { public static void main(String[] args) { int[] numbers = {2, 3, 1, 4}; int holder = 0; for(int i = 0; i < numbers.length; i++){ for(int j = 1; j < numbers.length; j++){ if(numbers[i] < numbers[j]){ holder = numbers[i]; numbers[i] = numbers[j]; numbers[j] = holder; } } } // prints array for(int i = 0; i < numbers.length; i++){ System.out.println(numbers[i]); } } } 结束该过程。即使您取消了该进程,也应该为此4 1 2 3 进行操作,这样就不会有zombie process徘徊了。 Python向您警告您没有wait

杀死wait后添加通话。