Using module 'subprocess' with timeout

后端 未结 29 2405
旧巷少年郎
旧巷少年郎 2020-11-21 15:15

Here\'s the Python code to run an arbitrary command returning its stdout data, or raise an exception on non-zero exit codes:

proc = subprocess.P         


        
29条回答
  •  长情又很酷
    2020-11-21 16:04

    Prepending the Linux command timeout isn't a bad workaround and it worked for me.

    cmd = "timeout 20 "+ cmd
    subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    (output, err) = p.communicate()
    

提交回复
热议问题