I have a Python Script B which is started by a subprocess.Popen call from my other Python Script A. This Python Script B runs a Selenium automation.
Now there are several cases that can occur while my subprocess B runs.
- The sricpt B finishes it's task at the end
- The script B crashes while executing
- The script A invokes a subprocess taskkill for script B
How can I now ensure that driver.quit() is executed in script B before any of these cases happen?
So I think in case 1. It's pretty straight forward, you simply call driver.quit() at the end. In case 2. you could run a try-except-finally
. Nevertheless, how would I ensure that driver.quit() is executed before/when the parent script A runs a taskkill command on B?
The taskkill is called in A.py as follows:
subprocess.call(['taskkill', '/F', '/T', '/PID', str(processB.pid)])