Using subprocess wait() and poll()

前端 未结 2 1102
终归单人心
终归单人心 2021-02-01 17:37

I am trying to write a small app that uses the subprocess module.

My program calls an external Bash command that takes some time to process. During this ti

2条回答
  •  囚心锁ツ
    2021-02-01 18:26

    @extraneon's answer is a little backwards. Both wait() and poll() return the process's exit code if the process has finished. The poll() method will return None if the process is still running and the wait() method will block until the process exits:

    Check out the following page: https://docs.python.org/3.4/library/subprocess.html#popen-objects

    Popen.poll()

    Check if child process has terminated. Set and return returncode attribute.

    Popen.wait()

    Wait for child process to terminate. Set and return returncode attribute.

提交回复
热议问题