python - Can't close processes using selenium threads -


i've been @ problem while , can't solve it. i'm making subprocesses, , subprocesses open more processes ( selenium webdrivers ). webdriver prone crash, built layered system main process make children, , kill/remake them when needed.

the issue i'm facing if run main thread , press ctrl+c children , children of children (the browsers) die. when try programatically whether ((popen) proc).kill(), i've tried sigint,sigterm. i've tried, .terminate, os.kill, os,killpg. no matter selenium processes won't die, moment hit ctrl+c, die.

code: here's how make threads. how cause issues?

proc = subprocess.popen( ["python" , module_path() + "/scraper.py"], stdout=subprocess.pipe ,stdin=subprocess.pipe)

so main question is, there way invoke ctrl+c effect happens in terminal. tried using threads kept deadlocking (why have no idea, had no shared memory, no dependencies). python not main language, precipitated.

thank you. kieran

in end solved it. changed program there manager process, , child process. manager spawned several children , children spawned selenium browsers. manager waits child crash , when child manager kills child kills selenium processes.

proc =  subprocess.popen( ["python" , path + "/pythonchild.py"], preexec_fn=os.setsid, stdout=subprocess.pipe ,stdin=subprocess.pipe) os.killpg( proc.pid, 9 ) 

the code above make , kill adding preexec starts new processes group, can terminated killing children.

hope helps someone!


Comments