如何处理无限挂起的命令

时间:2016-07-01 00:30:03

标签: python python-2.7

有没有办法通过command timeout选项proc = subprocess.Popen(cmd.split(' '), stderr=subprocess.PIPE)来终止无限期挂起的命令

import signal, os
import sys
import subprocess
import argparse
from subprocess import Popen, PIPE, STDOUT
import threading
from time import sleep
import time

from subprocess import Popen, PIPE, STDOUT
cmd = "python script.py -m loc"

proc = subprocess.Popen(cmd.split(' '), stderr=subprocess.PIPE)
print "Executing %s"%cmd
with proc.stderr:
    for line in iter(proc.stderr.readline, b''):
        print line,

print "process is done..." #doesn't print when command is hung

更新: -

我查看了以下门票,我没有找到关于如何使用subprocess32的明确示例,我在python文档中搜索过,仍然无法找到

Python subprocess timeout?

Using module 'subprocess' with timeout

0 个答案:

没有答案