mirror of
https://github.com/hanzoai/python-sdk.git
synced 2026-10-23 20:23:00 +00:00
feat(hanzo-mcp): v0.10.3 - add uvloop support for faster async
- Add uvloop>=0.21.0 to performance extras (Linux/macOS only) - Create event_loop utility for early uvloop configuration - Configure uvloop at CLI startup before async imports - Provides 2-4x faster event loop for async operations Install with: pip install hanzo-mcp[performance]
This commit is contained in:
@@ -15,6 +15,14 @@ import argparse
|
||||
from typing import Any, cast
|
||||
from pathlib import Path
|
||||
|
||||
# Configure uvloop early (before any async imports) for better performance
|
||||
# This is a no-op on Windows or if uvloop is not installed
|
||||
try:
|
||||
from hanzo_mcp.utils.event_loop import configure_event_loop
|
||||
configure_event_loop(quiet=True)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
# Import timeout parser (deferred to avoid early imports)
|
||||
def _parse_timeout_arg(timeout_str: str) -> float:
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
"""Event loop configuration with optional uvloop support.
|
||||
|
||||
This module provides utilities for configuring the asyncio event loop
|
||||
with optional uvloop support for improved performance on Linux/macOS.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
from typing import Optional
|
||||
|
||||
|
||||
def configure_event_loop(*, quiet: bool = False) -> Optional[str]:
|
||||
"""Configure the event loop with uvloop if available.
|
||||
|
||||
This should be called early in the application startup, before
|
||||
any async code runs.
|
||||
|
||||
Args:
|
||||
quiet: If True, suppress info messages about uvloop status
|
||||
|
||||
Returns:
|
||||
The name of the event loop policy being used, or None if default
|
||||
"""
|
||||
# uvloop is not available on Windows
|
||||
if sys.platform == "win32":
|
||||
return None
|
||||
|
||||
try:
|
||||
import uvloop
|
||||
|
||||
# Install uvloop as the default event loop policy
|
||||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
||||
|
||||
if not quiet:
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.debug(f"Using uvloop {uvloop.__version__} for event loop")
|
||||
|
||||
return f"uvloop-{uvloop.__version__}"
|
||||
|
||||
except ImportError:
|
||||
# uvloop not installed, use default asyncio event loop
|
||||
return None
|
||||
|
||||
|
||||
def get_event_loop_info() -> dict:
|
||||
"""Get information about the current event loop configuration.
|
||||
|
||||
Returns:
|
||||
Dictionary with event loop details
|
||||
"""
|
||||
try:
|
||||
loop = asyncio.get_event_loop()
|
||||
except RuntimeError:
|
||||
loop = None
|
||||
|
||||
info = {
|
||||
"loop_class": type(loop).__name__ if loop else None,
|
||||
"loop_module": type(loop).__module__ if loop else None,
|
||||
"platform": sys.platform,
|
||||
}
|
||||
|
||||
# Check if uvloop is being used
|
||||
try:
|
||||
import uvloop
|
||||
info["uvloop_available"] = True
|
||||
info["uvloop_version"] = uvloop.__version__
|
||||
info["using_uvloop"] = isinstance(
|
||||
asyncio.get_event_loop_policy(),
|
||||
uvloop.EventLoopPolicy
|
||||
)
|
||||
except ImportError:
|
||||
info["uvloop_available"] = False
|
||||
info["using_uvloop"] = False
|
||||
|
||||
return info
|
||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "hanzo-mcp"
|
||||
version = "0.10.2"
|
||||
version = "0.10.3"
|
||||
description = "The Zen of Hanzo MCP: One server to rule them all. The ultimate MCP that orchestrates all others."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
@@ -69,7 +69,7 @@ test = [
|
||||
]
|
||||
agents = ["hanzo-agents>=0.1.0"]
|
||||
memory = ["hanzo-memory>=1.0.0"]
|
||||
performance = ["ujson>=5.7.0", "orjson>=3.9.0"]
|
||||
performance = ["ujson>=5.7.0", "orjson>=3.9.0", "uvloop>=0.21.0; sys_platform != 'win32'"]
|
||||
publish = ["twine>=4.0.2", "build>=1.0.3"]
|
||||
|
||||
[project.scripts]
|
||||
|
||||
Generated
+3
-1
@@ -1232,7 +1232,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "hanzo-mcp"
|
||||
version = "0.10.2"
|
||||
version = "0.10.3"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "aiofiles" },
|
||||
@@ -1289,6 +1289,7 @@ memory = [
|
||||
performance = [
|
||||
{ name = "orjson" },
|
||||
{ name = "ujson" },
|
||||
{ name = "uvloop", marker = "sys_platform != 'win32'" },
|
||||
]
|
||||
publish = [
|
||||
{ name = "build" },
|
||||
@@ -1350,6 +1351,7 @@ requires-dist = [
|
||||
{ name = "typing-extensions", specifier = ">=4.13.0" },
|
||||
{ name = "ujson", marker = "extra == 'performance'", specifier = ">=5.7.0" },
|
||||
{ name = "uvicorn", specifier = ">=0.34.0" },
|
||||
{ name = "uvloop", marker = "sys_platform != 'win32' and extra == 'performance'", specifier = ">=0.21.0" },
|
||||
{ name = "watchdog", specifier = ">=6.0.0" },
|
||||
]
|
||||
provides-extras = ["dev", "docs", "analytics", "test", "agents", "memory", "performance", "publish"]
|
||||
|
||||
Reference in New Issue
Block a user