diff --git a/bot/__init__.py b/bot/__init__.py index aad4fcc6..6aa2128f 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -12,11 +12,11 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import asyncio import datetime import logging import os import random +import threading import aiohttp import asyncpg as asyncpg @@ -49,6 +49,8 @@ API_TOKEN = config('DISCORD_TOKEN') class Bot(commands.Bot): + threadLock = threading.Lock() + def __init__(self, **options): async def get_prefix(bot, message): @@ -88,16 +90,14 @@ class Bot(commands.Bot): async def create_connection(): """Setting up connection using asyncpg""" - - self.db = await asyncpg.create_pool( - host=host, - port=int(port), - user=user, - password=password, - database=db, - loop=self.loop) - - asyncio.run(create_connection()) + with self.threadLock: + self.db = await asyncpg.create_pool( + host=host, + port=int(port), + user=user, + password=password, + database=db, + loop=self.loop) async def startup_cache_log(): """Store the guilds/modmail systems in cache from the database on startup""" @@ -136,7 +136,7 @@ class Bot(commands.Bot): await pool.release(conn) # Establish Database Connection - # self.loop.run_until_complete(create_connection()) + self.loop.run_until_complete(create_connection()) # Load Information Into Cache self.loop.run_until_complete(startup_cache_log())