Performance
myProcessIsRunning = poll() is None
As suggested by the main answer, this is the recommended method and the easiest way to check if the process is working. (and it works in jython too)
If you do not have an instance of the process, check it out. Then use the TaskList / Ps operating processes.
In windows, my command will look like this:
filterByPid = "PID eq %s" % pid pidStr = str(pid) commandArguments = ['cmd', '/c', "tasklist", "/FI", filterByPid, "|", "findstr", pidStr ]
This essentially does the same as the following command line:
cmd /c "tasklist /FI "PID eq 55588" | findstr 55588"
And on linux, I do the same with:
pidStr = str(pid) commandArguments = ['ps', '-p', pidStr ]
The ps command already returns error code 0/1 depending on whether the process is found. In windows you need the find string command.
This is the same approach that is discussed in the flow of the following elements:
Check if a process is running using PID in JAVA
Note: If you use this approach, remember to wrap your command call in
try: foundRunningProcess = subprocess.check_output (argumentsArray, ** kwargs) return True except Exception as err: return False
Please note, be careful if you are developing VS code and using pure Python and Jython. In my environment, I was under the illusion that the poll () method did not work, because the process, which I suspected was supposed to end, was indeed running. This process launched Wildfly. And after I asked the wildfly to stop, the shell was still expecting the user to "Press any key to continue ...".
To complete this process, the following code worked on pure python:
process.stdin.write(os.linesep)
In jython, I had to fix this code to look like this:
print >>process.stdin, os.linesep
And with this difference, the process really ended. And jython.poll () started telling me that the process is indeed complete.