Added optional uvloop support.
uvloop uses libs used by node.js and has been shown to be a much more efficient event loop policy than the default Python asyncio implementation. If uvloop is installed, this is quietly changed before the bot is initialised. If uvloop cannot be set, either from not being installed, or from being used on an unsupported system such as Windoze, then nothing is changed. The only change should be a slight increase in throughput if it is detected. Please test first.
This commit is contained in:
parent
ffadea3e52
commit
e5858fecb3
13
run.py
13
run.py
@ -2,6 +2,7 @@
|
||||
# -*- coding: utf8 -*-
|
||||
|
||||
# Import packages
|
||||
import asyncio
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import json
|
||||
@ -11,6 +12,18 @@ import random
|
||||
# Import custom files
|
||||
from src.config.config import LoadConfig
|
||||
|
||||
# If uvloop is installed, change to that eventloop policy as it
|
||||
# is more efficient
|
||||
try:
|
||||
import uvloop
|
||||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
||||
del uvloop
|
||||
except BaseException as ex:
|
||||
print(f'Could not load uvloop. {type(ex).__name__}: {ex};',
|
||||
'reverting to default impl.')
|
||||
else:
|
||||
print(f'Using uvloop for asyncio event loop policy.')
|
||||
|
||||
|
||||
# Bot Class
|
||||
class SebiMachine(commands.Bot, LoadConfig):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user