0

I am unable to post code for this sorry, but I am trying to run a python script at all times from another python script which creates a system tray. This system tray will show if the program is correctly running or not.

I have tried a few methods so far, the most promising method has been using something like:

p = subprocess.Popen([xxx, xxx], stdout=PIPE, stderr=PIPE) 

Then I check if stderr has any output meaning there’s been an error.

However, this only works when I deliberately make an error occur (using the wrong file path) and nothing happens when I use the correct file path as the program never terminates.

So the main issue I’m having is that because I want the program to be running at all times it never terminates unless there’s an error. I want to be able to check that is it running so the user can check the status on the system tray.

martineau
  • 119,623
  • 25
  • 170
  • 301
epmxo
  • 1
  • 1
  • 3
    `p.poll()` will return `None` if the subprocess is still running, the exit code otherwise. – jasonharper Aug 20 '20 at 17:44
  • See the [`Popen.poll()`](https://docs.python.org/3/library/subprocess.html?highlight=poll#subprocess.Popen.poll) documentation. – martineau Aug 20 '20 at 17:46

1 Answers1

0

In Unix OS we use certain system calls for process management. The process is started when its parent process executes a fork system call. The parent process may then wait() for the child process to terminate either normally by using the exit() system call, or abnormally due to a fatal exception or signal (e.g., SIGTERM, SIGINT, SIGKILL), the exit status is returned to the OS and a SIGCHLD signal is sent to the parent process. The exit status can then be retrieved by the parent process via the wait system call to learn about what actually happened. Cheers

Khattak
  • 3
  • 3