【问题标题】:Selenium webdriver + PhantomJS processes not closingSelenium webdriver + PhantomJS 进程未关闭
【发布时间】:2014-11-11 15:34:12
【问题描述】:

这是您可以使用 webdriver 和 phantom 执行的最简单的打开和关闭操作: from selenium import webdriver crawler = webdriver.PhantomJS() crawler.set_window_size(1024,768) crawler.get('https://www.google.com/') crawler.quit()

在 Windows (7) 上,每次我运行我的代码来测试某些东西时,conhost.exe 和 phantomjs.exe 进程的新实例都会开始并且永远不会退出。我在这里做傻事吗?我认为当crawler.quit() 这样做时,进程会退出......

【问题讨论】:

标签: python selenium-webdriver phantomjs


【解决方案1】:

去图吧。问题通过重启解决。

【讨论】:

    【解决方案2】:

    重新启动不是解决此问题的方法。我已经在 LINUX 系统中试验了这个 hack。尝试修改service.py中定义的stop()函数

    def stop(self):
        """
        Cleans up the process
        """
        if self._log:
            self._log.close()
            self._log = None
        #If its dead dont worry
        if self.process is None:
            return
    
        #Tell the Server to properly die in case
        try:
            if self.process:
                self.process.stdin.close()
                #self.process.kill()
                self.process.send_signal(signal.SIGTERM)
                self.process.wait()
                self.process = None
        except OSError:
            # kill may not be available under windows environment
            pass
    

    显式添加了行send_signal 以发出退出phantomjs 进程的信号。不要忘记在此文件的开头添加import signal 语句。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-02
      • 1970-01-01
      • 2016-08-06
      • 2015-09-25
      • 2018-03-09
      相关资源
      最近更新 更多