From a3d8d4011fe432d7c83b80ecac8e678257b384f0 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Thu, 2 Aug 2018 10:58:36 -0400 Subject: [PATCH] Add `uvloop.install()` helper function. --- uvloop/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/uvloop/__init__.py b/uvloop/__init__.py index f37c69e..49c8d44 100644 --- a/uvloop/__init__.py +++ b/uvloop/__init__.py @@ -1,4 +1,4 @@ -import asyncio +import asyncio as __asyncio from asyncio.events import BaseDefaultEventLoopPolicy as __BasePolicy @@ -8,10 +8,10 @@ from .loop import Loop as __BaseLoop # NOQA __version__ = '0.12.0.dev0' -__all__ = ('new_event_loop', 'EventLoopPolicy') +__all__ = ('new_event_loop', 'install', 'EventLoopPolicy') -class Loop(__BaseLoop, asyncio.AbstractEventLoop): +class Loop(__BaseLoop, __asyncio.AbstractEventLoop): pass @@ -20,6 +20,11 @@ def new_event_loop(): return Loop() +def install(): + """A helper function to install uvloop policy.""" + __asyncio.set_event_loop_policy(EventLoopPolicy()) + + class EventLoopPolicy(__BasePolicy): """Event loop policy.