Using module 'subprocess' with timeout

后端 未结 29 2425
旧巷少年郎
旧巷少年郎 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:15

    surprised nobody mentioned using timeout

    timeout 5 ping -c 3 somehost

    This won't for work for every use case obviously, but if your dealing with a simple script, this is hard to beat.

    Also available as gtimeout in coreutils via homebrew for mac users.

提交回复
热议问题