相关疑难解决方法(0)

捕获`KeyboardInterrupt`而不关闭Python中的Selenium Webdriver会话

Python程序通过Selenium WebDriver驱动Firefox.代码嵌入在try/ exceptblock中,如下所示:

session = selenium.webdriver.Firefox(firefox_profile)
try:
    # do stuff
except (Exception, KeyboardInterrupt) as exception:
    logging.info("Caught exception.")
    traceback.print_exc(file=sys.stdout)
Run Code Online (Sandbox Code Playgroud)

如果程序因错误而中止,则WebDriver会话不会关闭,因此Firefox窗口保持打开状态.但是如果程序以KeyboardInterrupt异常中止,则Firefox窗口会关闭(我想因为WebDriver会话也被释放了),我想避免这种情况.

我知道两个异常都通过相同的处理程序,因为我"Caught exception"在两种情况下都看到了消息.

我怎么能避免关闭Firefox窗口KeyboardInterrupt

python keyboardinterrupt selenium-webdriver

19
推荐指数
1
解决办法
1461
查看次数

如何阻止SIGINT传递给python中的子进程?

我的python脚本用信号处理模块拦截SIGINT信号以防止过早退出,但是这个信号被传递给我用Popen打开的子进程.是否有一些方法可以防止将此信号传递给子进程,以便在用户按下ctrl-c时也不会过早退出?

python subprocess signals sigint intercept

13
推荐指数
2
解决办法
3997
查看次数