Make uvloop dependency optional

This commit is contained in:
miruka
2019-08-30 20:24:13 -04:00
parent 446dc776b0
commit ca2ecc75bb
3 changed files with 18 additions and 4 deletions

View File

@@ -6,7 +6,6 @@ from operator import attrgetter
from threading import Thread
from typing import Coroutine, Sequence
import uvloop
from appdirs import AppDirs
from . import __about__, pyotherside
@@ -14,6 +13,15 @@ from .pyotherside_events import CoroutineDone
log.getLogger().setLevel(log.INFO)
try:
import uvloop
except ModuleNotFoundError:
UVLOOP = False
log.info("uvloop not available, using default asyncio loop.")
else:
UVLOOP = True
log.info("uvloop is available.")
class App:
def __init__(self) -> None:
@@ -51,7 +59,10 @@ class App:
def _loop_starter(self) -> None:
asyncio.set_event_loop(self.loop)
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
if UVLOOP:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
self.loop.run_forever()