mirror of
https://github.com/NanmiCoder/MediaCrawler.git
synced 2026-06-01 23:47:27 +08:00
Merge pull request #901 from Jaryan-luck/main
修复:WebUI环境检查因Asyncio Windows兼容性而失败并且无任何错误提示
This commit is contained in:
37
api/main.py
37
api/main.py
@@ -23,6 +23,7 @@ Or: python -m api.main
|
|||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
@@ -85,17 +86,29 @@ async def check_environment():
|
|||||||
"""Check if MediaCrawler environment is configured correctly"""
|
"""Check if MediaCrawler environment is configured correctly"""
|
||||||
try:
|
try:
|
||||||
# Run uv run main.py --help command to check environment
|
# Run uv run main.py --help command to check environment
|
||||||
process = await asyncio.create_subprocess_exec(
|
if sys.platform == "win32":
|
||||||
"uv", "run", "main.py", "--help",
|
loop = asyncio.get_running_loop()
|
||||||
stdout=subprocess.PIPE,
|
process = await loop.run_in_executor(
|
||||||
stderr=subprocess.PIPE,
|
None,
|
||||||
cwd="." # Project root directory
|
lambda: subprocess.run(
|
||||||
)
|
["uv", "run", "main.py", "--help"],
|
||||||
stdout, stderr = await asyncio.wait_for(
|
capture_output=True,
|
||||||
process.communicate(),
|
timeout=30.0,
|
||||||
timeout=30.0 # 30 seconds timeout
|
cwd="."
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
stdout, stderr = process.stdout, process.stderr # bytes
|
||||||
|
else:
|
||||||
|
process = await asyncio.create_subprocess_exec(
|
||||||
|
"uv", "run", "main.py", "--help",
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
cwd="." # Project root directory
|
||||||
|
)
|
||||||
|
stdout, stderr = await asyncio.wait_for(
|
||||||
|
process.communicate(),
|
||||||
|
timeout=30.0 # 30 seconds timeout
|
||||||
|
)
|
||||||
if process.returncode == 0:
|
if process.returncode == 0:
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
@@ -125,7 +138,7 @@ async def check_environment():
|
|||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"message": "Environment check error",
|
"message": "Environment check error",
|
||||||
"error": str(e)
|
"error": f"{type(e).__name__}: {str(e) or 'Unknown'}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user