Selenium webdriver + PhantomJS processes not closing

只愿长相守 提交于 2019-12-11 07:52:06

问题


Here's just about the simplest open and close you can do with webdriver and phantom: from selenium import webdriver crawler = webdriver.PhantomJS() crawler.set_window_size(1024,768) crawler.get('https://www.google.com/') crawler.quit()

On windows (7), every time I run my code to test something out, new instances of the conhost.exe and phantomjs.exe processes begin and never quit. Am I doing something stupid here? I figured the processes would quit when the crawler.quit() did...


回答1:


Go figure. Problem resolved with a reboot.




回答2:


Rebooting is not a solution for this problem. I have experimented this hack in LINUX system. Try modifying the stop() function defined in service.py

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

Added line send_signal explicitly to give the signal to quit phantomjs process. Don't forget to add import signal statement at start of this file.



来源:https://stackoverflow.com/questions/26868492/selenium-webdriver-phantomjs-processes-not-closing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!