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

@ -42,7 +42,11 @@ Install the Python 3 dependencies from Pypi:
pip3 install --user --upgrade \
Pillow aiofiles appdirs dataclasses filetype hsluv html_sanitizer \
lxml mistune uvloop
lxml mistune
Optional dependency for performance improvements:
pip3 install --user --upgrade uvloop
Install the Python 3 dependencies from Github:

View File

@ -11,7 +11,6 @@
- When qml syntax highlighting supports ES6 string interpolation, use them
- Fixes
- Make uvloop optional
- Backspace bug
- Show error if uploading avatar fails or file is corrupted

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()