How to properly stop phantomjs execution

前端 未结 7 888
星月不相逢
星月不相逢 2020-11-29 21:30

I initiated and close phantomjs in Python with the following

from selenium import webdriver    
driver = webdriver.PhantomJS()
driver.get(url)
h         


        
7条回答
  •  攒了一身酷
    2020-11-29 22:07

    What is the OS you are using? I think it corresponds to the case of the next, if you are using the POSIX OS.

    I create pull request, but it rejected. https://github.com/SeleniumHQ/selenium/pull/2244

    But I think obviously the correct it. Therefore , I issued a issue. https://github.com/SeleniumHQ/selenium/issues/2272

    The root cause of this problem is that the end method of ghost driver mode phatmojs is incorrect. It is not not use the shutdown API of ghost driver mode phantomjs at the end.

    In the case of phantomjs that you installed in npm on Linux or OSX, A selenium call Popen for phantomjs, A phantomjs call spawn for lib/phantomjs.js. At this time, a selenium is parent, a phantomjs is child, and lib/phantomjs.js is grandchild.

    You call quit() in parent(selenium), it send SIGTERM to child(phantomjs). and a child(phantomjs) send SIGTERM to grandchild(lib/phantomjs.js) in the child's SIGTERM handler function.

    A grandchild will be zombie when parent send SIGKILL to child before the child send SIGTERM to grandchild.

    This pull request ttps://github.com/SeleniumHQ/selenium/pull/2244 be shutdown using ghost driver mode shutdown api.

     def send_remote_shutdown_command(self):
          super(Service, self).send_remote_shutdown_command()  ## ADD A NEW LINE HERE
          if self._cookie_temp_file:
              os.close(self._cookie_temp_file_handle)
              os.remove(self._cookie_temp_file)
    

    Other solutions, sleep between "self.process.ternimate()" and "self.process.kill()". ttps://github.com/SeleniumHQ/selenium/blob/051c8b110a1aec35247cd45fa4db85c6e522cdcb/py/selenium/webdriver/common/service.py#L151-L153

            self.process.terminate()
            time.sleep(1)  ## ADD A NEW LINE HERE
            self.process.kill()
            self.process.wait()
    

提交回复
热议问题