小编Cod*_*ger的帖子

Python:在后台进程上使用popen poll

我在后台运行一个很长的进程(实际上是另一个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.

python subprocess popen python-3.x

16
推荐指数
3
解决办法
5万
查看次数

标签 统计

popen ×1

python ×1

python-3.x ×1

subprocess ×1