2.7.1修复使用Anaconda中关闭driver时的小问题

This commit is contained in:
g1879 2022-06-23 11:30:50 +08:00
parent caca993c6a
commit ee61f1d8bd
4 changed files with 17 additions and 13 deletions

View File

@ -370,13 +370,14 @@ def get_pid_from_port(port: Union[str, int]) -> Union[str, None]:
:param port: 端口号
:return: 进程id
"""
from os import popen
from platform import system
if system().lower() != 'windows' or port is None:
return None
from os import popen
from time import perf_counter
if system().lower() != 'windows' or port is None:
return
try: # 避免Anaconda中可能产生的报错
process = popen(f'netstat -ano |findstr {port}').read().split('\n')[0]
t = perf_counter()
@ -385,6 +386,9 @@ def get_pid_from_port(port: Union[str, int]) -> Union[str, None]:
return process.split(' ')[-1] or None
except AttributeError:
return None
def get_usable_path(path: Union[str, Path]) -> Path:
"""检查文件或文件夹是否有重名,并返回可以使用的路径 \n

View File

@ -504,7 +504,7 @@ def _create_driver(chrome_path: str, driver_path: str, options: Options) -> WebD
def _get_chrome_hwnds_from_pid(pid) -> list:
# 通过PID查询句柄ID
"""通过PID查询句柄ID"""
try:
from win32gui import IsWindow, GetWindowText, EnumWindows
from win32process import GetWindowThreadProcessId
@ -524,7 +524,7 @@ def _get_chrome_hwnds_from_pid(pid) -> list:
def _kill_progress(pid: str = None, port: int = None) -> bool:
"""获取端口号第一条进程的pid \n
"""关闭浏览器进程 \n
:param pid: 进程id
:param port: 端口号如没有进程id从端口号获取
:return: 是否成功

View File

@ -1,4 +1,4 @@
# v2.7.0
# v2.7.1
- DriverPage

View File

@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
setup(
name="DrissionPage",
version="2.7.0",
version="2.7.1",
author="g1879",
author_email="g1879@qq.com",
description="A module that integrates selenium and requests session, encapsulates common page operations.",