Update main.py

修复Asyncio Windows兼容性
This commit is contained in:
🐟Jaryán🍋
2026-05-20 22:54:27 +08:00
committed by GitHub
parent 9311d21f1f
commit 5ddd969a8e

View File

@@ -85,6 +85,19 @@ 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
if sys.platform == "win32":
loop = asyncio.get_running_loop()
process = await loop.run_in_executor(
None,
lambda: subprocess.run(
["uv", "run", "main.py", "--help"],
capture_output=True,
timeout=30.0,
cwd="."
)
)
stdout, stderr = process.stdout, process.stderr # bytes
else:
process = await asyncio.create_subprocess_exec( process = await asyncio.create_subprocess_exec(
"uv", "run", "main.py", "--help", "uv", "run", "main.py", "--help",
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
@@ -95,7 +108,6 @@ async def check_environment():
process.communicate(), process.communicate(),
timeout=30.0 # 30 seconds timeout timeout=30.0 # 30 seconds timeout
) )
if process.returncode == 0: if process.returncode == 0:
return { return {
"success": True, "success": True,
@@ -125,7 +137,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'}"
} }