1

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...

AutomaticStatic
  • 1,661
  • 3
  • 21
  • 42
  • Cf. https://stackoverflow.com/questions/25110624/how-to-properly-stop-phantomjs-execution https://github.com/SeleniumHQ/selenium/issues/767 – Nemo Aug 23 '18 at 04:59

2 Answers2

0

Go figure. Problem resolved with a reboot.

AutomaticStatic
  • 1,661
  • 3
  • 21
  • 42
0

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.

Tanu
  • 1,503
  • 12
  • 21