Python subprocess timeout?

后端 未结 10 2123
旧时难觅i
旧时难觅i 2020-12-09 04:06

Is there any argument or options to setup a timeout for Python\'s subprocess.Popen method?

Something like this:

subprocess.Popen([\'..\'], ..., timeout

10条回答
  •  一生所求
    2020-12-09 04:35

    Yes, https://pypi.python.org/pypi/python-subprocess2 will extend the Popen module with two additional functions,

    Popen.waitUpTo(timeout=seconds)
    

    This will wait up to acertain number of seconds for the process to complete, otherwise return None

    also,

    Popen.waitOrTerminate
    

    This will wait up to a point, and then call .terminate(), then .kill(), one orthe other or some combination of both, see docs for full details:

    http://htmlpreview.github.io/?https://github.com/kata198/python-subprocess2/blob/master/doc/subprocess2.html

提交回复
热议问题