I am trying to start a java process that is meant to take a long time, using python's subprocess
module.
What I am actually doing is using the multiprocessing
module to start a new Process, and using that process, use subprocess
module to run java -jar
.
This works fine, but when I start the new process, the java process replaces the python process running python Process
. I would like java
to run as a child process in a way that when the process that started a new multiprocessing.Process
died, the process running java
would die too.
Is this possible?
Thanks.
Edit: here's some code to clarify my question:
def run_task():
pargs = ["java -jar app.jar"]
p = Popen(pargs)
p.communicate()[0]
return p
while(True):
a = a_blocking_call()
process = Process(target=run_task)
process.start()
if not a:
break
I want the process running run_task
to be killed along with the process running java
when the process executing the while loop reaches the break
line. Is this possible?