Is there a way to check if a subprocess is still running?

后端 未结 4 1274
难免孤独
难免孤独 2020-11-29 01:45

I\'m launching a number of subprocesses with subprocess.Popen in Python. I\'d like to check whether one such process has completed. I\'ve found two ways of checking the stat

4条回答
  •  心在旅途
    2020-11-29 01:58

    Ouestion: ... a way to check if a process is still running ...

    You can do it for instance:

    p = subprocess.Popen(...
    """
    A None value indicates that the process hasn't terminated yet.
    """
    poll = p.poll()
    if poll == None:
      # p.subprocess is alive
    

    Python » 3.6.1 Documentation popen-objects

    Tested with Python:3.4.2

提交回复
热议问题