I noticed that sometimes python does not kill child processes after Popen and finishing script.
The code:
proc = subprocess.Popen([blablabla_dir + 'blablabla'],
stdin=None, stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
cwd = None,
env = {'LD_LIBRARY_PATH': blablabla_dir + 'lib'})
raise Exception()
Result:
...
raise Exception()
Exception
But sometimes I have:
$ ps aux | grep blablabla
symonen+ 2413 0.0 0.1 158572 11988 ? Sl 19:04 0:00 /home/qqq/dev/eee/build/debug/blablabla
symonen+ 2591 0.0 0.0 18636 944 pts/12 S+ 19:04 0:00 grep --color=auto blablabla
So we have: if python "have time" to close process (after throw exception) then process finished. If not then not finished
So question: is there exist way to make force kill all child processes after finishing script (e.g. some option for script running or some else way). I'm making some tests for my applications and do not want to have garbage in system after finishing of my test's script.
I mean some ways only by Pyhon. So like "run script from bush script and then kill all garbage from bush script" - unsuitable.
Send to all created processes signal (15 or 9) from me is not good way. More precisely it is an option, but it does not solve the problem completely. Of course I closes my applications by signals. But: if we had unhandled exception before sending of kill then after script finishing we will have garbage again.