0

I have the following subprocess.

ss = subprocess.Popen(["python3", "-m", "unittest", totest], 
                      stdin=None, 
                      stdout=subprocess.PIPE,  
                      stderr=subprocess.PIPE)

I want to know if it has started or it had thrown errors.

Tek Nath Acharya
  • 1,676
  • 2
  • 20
  • 35
  • I think the process is started right away, as OS schedules it. You can check if it is ended or not using something like `subprocess.poll` or `subprocess.communicate` – Pratik Sep 05 '19 at 12:14
  • 2
    Possible duplicate of [Is there a way to check if a subprocess is still running?](https://stackoverflow.com/questions/43274476/is-there-a-way-to-check-if-a-subprocess-is-still-running) – Daemon Painter Sep 05 '19 at 12:14
  • 1
    I don't think it is a duplicate of that. The other question asks if the process still runs. This one asks if the process already runs. – glglgl Sep 06 '19 at 05:48
  • @glglgl Yes, I asked that – Tek Nath Acharya Sep 06 '19 at 06:20

1 Answers1

0

If the call returns normally, you can consider the process started. If the process cannot start for any reason, the Popen() call throws an exception.

glglgl
  • 89,107
  • 13
  • 149
  • 217