C
chengiz
Hi,
I'm trying to run a process from a python script. I need the exit
status of that process but do not care about its output, so until now
was using os.system(). But it turned out that the process often went
into an infinite loop, so I wrote a SIGALRM handler. Unfortunately the
code I came up with is quite kludgy:
import subprocess
....
try:
p = subprocess.Popen(..., shell = True)
pid = p.pid
os.waitpid(pid...)
...
except ...: # Thrown by alarm signal handler
os.kill(pid + 1) # "Real" pid = shell pid + 1
...
The os.kill is very hacky and unsafe so I was looking for better
ideas. Any help will be greatly appreciated. Thanks!
I'm trying to run a process from a python script. I need the exit
status of that process but do not care about its output, so until now
was using os.system(). But it turned out that the process often went
into an infinite loop, so I wrote a SIGALRM handler. Unfortunately the
code I came up with is quite kludgy:
import subprocess
....
try:
p = subprocess.Popen(..., shell = True)
pid = p.pid
os.waitpid(pid...)
...
except ...: # Thrown by alarm signal handler
os.kill(pid + 1) # "Real" pid = shell pid + 1
...
The os.kill is very hacky and unsafe so I was looking for better
ideas. Any help will be greatly appreciated. Thanks!