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:
404 2018-05-21 13:54:54 +01:00 committed by GitHub
parent ffadea3e52
commit e5858fecb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

13
run.py
View File

@ -2,6 +2,7 @@
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
# Import packages # Import packages
import asyncio
import discord import discord
from discord.ext import commands from discord.ext import commands
import json import json
@ -11,6 +12,18 @@ import random
# Import custom files # Import custom files
from src.config.config import LoadConfig 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 # Bot Class
class SebiMachine(commands.Bot, LoadConfig): class SebiMachine(commands.Bot, LoadConfig):