Thursday, September 9, 2010

programmatically executing and terminating a long-running batch process in python

Programmer Question

Hi guys,



I have been searching for a way to start and terminate a long-running "batch jobs" in python. Right now I'm using "os.system()" to launch a long-running batch job inside each child process. As you might have guessed, "os.system()" spawns a new process inside that child process (grandchild process?), so I cannot kill the batch job from the grand-parent process. To provide some visualization of what I have just described:



Main (grandparent) process, with PID = AAAA
|
|------> child process with PID = BBBB
|
|------> os.system("some long-running batch file)
[grandchild process, with PID = CCCC]


So, my problem is I cannot kill the grandchild process from the grandparent...



My question is, is there a way to start a long-running batch job inside a child process, and being able to kill that batch job by just terminating the child process?
What are the alternatives to os.system() that I can use so that I can kill the batch-job from the main process ?



Thanks !!



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails