'Python monitor process by pid

I'm looking for better idea than my or may be you can show me where I made a mistake. What I'm trying to do.

  1. I try to run process with subprocess and thread it is run good and no mistakes here found, one thing that's command in Linux has timeout.
  2. I got pid 3.Than I would like monitor proc by pid, and when it finished do some stuff
def monitor_func(my_obj):
               print(my_obj.process_pid)
               sleep(20)
               while os.kill(my_obj.process_pid, 0) is None:
                     print("proc is running")
                     try:
                         os.kill(my_obj.process_pid, 0)
                     except OSError:
                         continue
               else:
                      print("proc is stopped")

What is the problem? While loop works in infinite. os.kill(my_obj.process_pid, 0) always returns NONE Thank you in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source