Reputation: 569
I have a URL in a while loop which repeats the process. Is it possible to bind a key to stop a selenium python script from running while still keeping chromedriver open?
Upvotes: 0
Views: 260
Reputation: 41119
You can use a try/except block that catches a KeyboardInterrupt
exception (IE when you input ctrl + c
to the terminal/command prompt)
try:
while True:
#dostuff
except KeyboardInterrupt:
print("Loop stopped!")
You may also want to consider launching your script in interactive mode, which will prevent the console from closing and will keep the interpreter open after the completion (or failure) of the script, thereby preventing the teardown/cleanup that closes the webdriver instance.
Upvotes: 1