mirror of
https://github.com/zhinianboke/xianyu-auto-reply.git
synced 2025-08-31 01:38:48 +08:00
Update XianyuAutoAsync.py
This commit is contained in:
parent
bf619985e7
commit
29b41864e5
@ -3268,12 +3268,18 @@ class XianyuLive:
|
|||||||
async def _execute_cookie_refresh(self, current_time):
|
async def _execute_cookie_refresh(self, current_time):
|
||||||
"""独立执行Cookie刷新任务,避免阻塞主循环"""
|
"""独立执行Cookie刷新任务,避免阻塞主循环"""
|
||||||
try:
|
try:
|
||||||
success = await self._refresh_cookies_via_browser()
|
# 为整个Cookie刷新任务添加超时保护(5分钟)
|
||||||
|
success = await asyncio.wait_for(
|
||||||
|
self._refresh_cookies_via_browser(),
|
||||||
|
timeout=300.0 # 5分钟超时
|
||||||
|
)
|
||||||
if success:
|
if success:
|
||||||
self.last_cookie_refresh_time = current_time
|
self.last_cookie_refresh_time = current_time
|
||||||
logger.info(f"【{self.cookie_id}】Cookie刷新任务完成")
|
logger.info(f"【{self.cookie_id}】Cookie刷新任务完成")
|
||||||
else:
|
else:
|
||||||
logger.warning(f"【{self.cookie_id}】Cookie刷新任务失败")
|
logger.warning(f"【{self.cookie_id}】Cookie刷新任务失败")
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
logger.error(f"【{self.cookie_id}】Cookie刷新任务超时(5分钟)")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"【{self.cookie_id}】执行Cookie刷新任务异常: {self._safe_str(e)}")
|
logger.error(f"【{self.cookie_id}】执行Cookie刷新任务异常: {self._safe_str(e)}")
|
||||||
|
|
||||||
@ -3331,13 +3337,28 @@ class XianyuLive:
|
|||||||
asyncio.set_event_loop_policy(DockerEventLoopPolicy())
|
asyncio.set_event_loop_policy(DockerEventLoopPolicy())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
playwright = await async_playwright().start()
|
# 添加超时机制,避免无限等待
|
||||||
|
playwright = await asyncio.wait_for(
|
||||||
|
async_playwright().start(),
|
||||||
|
timeout=30.0 # 30秒超时
|
||||||
|
)
|
||||||
|
logger.debug(f"【{self.cookie_id}】Docker环境下Playwright启动成功")
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
logger.error(f"【{self.cookie_id}】Docker环境下Playwright启动超时")
|
||||||
|
return False
|
||||||
finally:
|
finally:
|
||||||
# 恢复原策略
|
# 恢复原策略
|
||||||
asyncio.set_event_loop_policy(old_policy)
|
asyncio.set_event_loop_policy(old_policy)
|
||||||
else:
|
else:
|
||||||
# 非Docker环境,正常启动
|
# 非Docker环境,正常启动(也添加超时保护)
|
||||||
playwright = await async_playwright().start()
|
try:
|
||||||
|
playwright = await asyncio.wait_for(
|
||||||
|
async_playwright().start(),
|
||||||
|
timeout=30.0 # 30秒超时
|
||||||
|
)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
logger.error(f"【{self.cookie_id}】Playwright启动超时")
|
||||||
|
return False
|
||||||
|
|
||||||
# 启动浏览器(参照商品搜索的配置)
|
# 启动浏览器(参照商品搜索的配置)
|
||||||
browser_args = [
|
browser_args = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user