Skip to content

Commit

Permalink
Asynchronously load api.py, create asyncio task, fire and forget.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeyUsersREC authored Nov 21, 2023
1 parent 132807d commit 6988c0f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1484,14 +1484,20 @@ async def start_server(self):

async def stop_server(self):
await self.server.shutdown()

def _run_and_discard(self, task):
asyncio.run(asyncio.to_thread(task))

async def cog_load(self) -> None:
# asyncio.run_coroutine_threadsafe(self.start_server(), self.bot.loop)

try:
await self.start_server()
task = asyncio.create_task(self.start_server())
self._run_and_discard(task)
except:
# print('REALLY BAD ERROR.')
pass

async def cog_unload(self) -> None:
await self.stop_server()

Expand Down

0 comments on commit 6988c0f

Please sign in to comment.