We are running a java process, we want to stop execution after timeout, on timeout we get exception for timeout but java process is still running in background since we are using shell=True
Here is similar example
subprocess.run("ping 8.8.8.8",timeout=1, shell=True,)
however after timeout child process is still running
subprocess.TimeoutExpired: Command 'ping 8.8.8.8' timed out after 0.9998808979980822 seconds 64 bytes from 8.8.8.8: icmp_seq=2 ttl=122 time=10.7 ms 64 bytes from 8.8.8.8: icmp_seq=3 ttl=122 time=10.1 ms
Some post suggested to drop shell=True
, this does work for simple case, however for our java program we want to specify JAVA_OPTS but without shell we cannot set environment variables.
Is there a way to use subprocess.run
which would kill child process post timeout expires