From fa918f105a1e7f35a368094563aa134bf881fa46 Mon Sep 17 00:00:00 2001 From: g1879 Date: Thu, 24 Aug 2023 10:05:46 +0800 Subject: [PATCH] =?UTF-8?q?quit()=E4=BC=9A=E7=AD=89=E5=BE=85=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=E8=BF=9B=E7=A8=8B=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/chromium_page.py | 14 ++++++++++---- DrissionPage/web_page.py | 3 +-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/DrissionPage/chromium_page.py b/DrissionPage/chromium_page.py index 936243e..6158afd 100644 --- a/DrissionPage/chromium_page.py +++ b/DrissionPage/chromium_page.py @@ -9,7 +9,6 @@ from .chromium_base import ChromiumBase, Timeout from .chromium_driver import ChromiumDriver from .chromium_tab import ChromiumTab from .commons.browser import connect_browser -from .commons.tools import port_is_using from .configs.chromium_options import ChromiumOptions from .errors import BrowserConnectError from .setter import ChromiumPageSetter @@ -338,9 +337,16 @@ class ChromiumPage(ChromiumBase): """关闭浏览器""" self._tab_obj.call_method('Browser.close') self._tab_obj.stop() - ip, port = self.address.split(':') - while port_is_using(ip, port): - sleep(.1) + + if self.process_id: + from os import popen + from platform import system + txt = f'tasklist | findstr {self.process_id}' if system().lower() == 'windows' \ + else f'ps -ef | grep {self.process_id}' + while True: + p = popen(txt) + if f' {self.process_id} ' not in p.read(): + break def _on_alert_close(self, **kwargs): """alert关闭时触发的方法""" diff --git a/DrissionPage/web_page.py b/DrissionPage/web_page.py index b36b09c..ec8a872 100644 --- a/DrissionPage/web_page.py +++ b/DrissionPage/web_page.py @@ -421,8 +421,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage): self._response = None self._has_session = None if self._has_driver: - self._tab_obj.call_method('Browser.close') - self._tab_obj.stop() + super(SessionPage, self).quit() self._tab_obj = None self._has_driver = None