eventloop: add support for uvloop

Signed-off-by:  Eric Callahan <arskine.code@gmail.com>
This commit is contained in:
Eric Callahan 2023-06-27 08:00:13 -04:00
parent f99e5b0bea
commit 51f4d4b888
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
3 changed files with 14 additions and 1 deletions

View File

@ -22,6 +22,7 @@ from typing import (
Coroutine,
Dict,
Set,
cast
)
if TYPE_CHECKING:
from ..confighelper import ConfigHelper
@ -61,8 +62,8 @@ class ShellCommandProtocol(asyncio.subprocess.SubprocessStreamProtocol):
def connection_made(
self, transport: asyncio.transports.BaseTransport
) -> None:
transport = cast(asyncio.SubprocessTransport, transport)
self._transport = transport
assert isinstance(transport, asyncio.SubprocessTransport)
stdout_transport = transport.get_pipe_transport(1)
if stdout_transport is not None:
self._pipe_fds.append(1)

View File

@ -5,6 +5,8 @@
# This file may be distributed under the terms of the GNU GPLv3 license
from __future__ import annotations
import os
import contextlib
import asyncio
import inspect
import functools
@ -21,12 +23,21 @@ from typing import (
Union
)
_uvl_var = os.getenv("MOONRAKER_ENABLE_UVLOOP", "y").lower()
_uvl_enabled = False
if _uvl_var in ["y", "yes", "true"]:
with contextlib.suppress(ImportError):
import uvloop
uvloop.install()
_uvl_enabled = True
if TYPE_CHECKING:
_T = TypeVar("_T")
FlexCallback = Callable[..., Optional[Awaitable]]
TimerCallback = Callable[[float], Union[float, Awaitable[float]]]
class EventLoop:
UVLOOP_ENABLED = _uvl_enabled
TimeoutError = asyncio.TimeoutError
def __init__(self) -> None:
self.reset()

View File

@ -586,6 +586,7 @@ def main(from_package: bool = True) -> None:
app_args["log_file"] = str(data_path.joinpath("logs/moonraker.log"))
app_args["python_version"] = sys.version.replace("\n", " ")
app_args["msgspec_enabled"] = json_wrapper.MSGSPEC_ENABLED
app_args["uvloop_enabled"] = EventLoop.UVLOOP_ENABLED
log_manager = LogManager(app_args, startup_warnings)
# Start asyncio event loop and server