From e622e56b3901868895ff1f5c62f37ad9b0262b98 Mon Sep 17 00:00:00 2001 From: "guorong.zheng" <360996299@qq.com> Date: Mon, 2 Dec 2024 11:20:28 +0800 Subject: [PATCH] fix:get speed(#600,#606) --- utils/speed.py | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/utils/speed.py b/utils/speed.py index 00d21035ff..1760357bea 100644 --- a/utils/speed.py +++ b/utils/speed.py @@ -7,8 +7,6 @@ from utils.tools import is_ipv6, remove_cache_info, get_resolution_value, get_logger import subprocess import yt_dlp -from concurrent.futures import ProcessPoolExecutor -import functools logger = get_logger(constants.log_path) @@ -34,24 +32,17 @@ async def get_speed_yt_dlp(url, timeout=config.sort_timeout): Get the speed of the url by yt_dlp """ try: - async with asyncio.timeout(timeout + 2): - start_time = time() - loop = asyncio.get_running_loop() - with ProcessPoolExecutor() as exc: - info = await loop.run_in_executor( - exc, functools.partial(get_info_yt_dlp, url, timeout) - ) - fps = ( - int(round((time() - start_time) * 1000)) - if len(info) - else float("inf") - ) - resolution = ( - f"{info['width']}x{info['height']}" - if "width" in info and "height" in info - else None - ) - return (fps, resolution) + start_time = time() + info = await asyncio.wait_for( + asyncio.to_thread(get_info_yt_dlp, url, timeout), timeout=timeout + ) + fps = int(round((time() - start_time) * 1000)) if len(info) else float("inf") + resolution = ( + f"{info['width']}x{info['height']}" + if "width" in info and "height" in info + else None + ) + return (fps, resolution) except: return (float("inf"), None)