def _try_use_uvloop()

in src/dubbo/remoting/aio/event_loop.py [0:0]


def _try_use_uvloop() -> None:
    """
    Use uvloop instead of the default asyncio running_loop.
    """
    import asyncio
    import os

    # Check if the operating system.
    if os.name == "nt":
        # Windows is not supported.
        _LOGGER.warning("Unable to use uvloop, because it is not supported on your operating system.")
        return

    # Try import uvloop.
    try:
        import uvloop
    except ImportError:
        # uvloop is not available.
        _LOGGER.warning(
            "Unable to use uvloop, because it is not installed. You can install it by running `pip install uvloop`."
        )
        return

    # Use uvloop instead of the default asyncio running_loop.
    if not isinstance(asyncio.get_event_loop_policy(), uvloop.EventLoopPolicy):
        asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())