我在后台运行一个很长的进程(实际上是另一个python脚本).我需要知道它什么时候结束.我发现Popen.poll()总是为后台进程返回0.还有另一种方法吗?
p = subprocess.Popen("sleep 30 &", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
a = p.poll()
print(a)
Run Code Online (Sandbox Code Playgroud)
上面的代码从不打印None.