diff --git a/lavalink/lavalink.py b/lavalink/lavalink.py index a9f61882..1c1b4270 100644 --- a/lavalink/lavalink.py +++ b/lavalink/lavalink.py @@ -4,7 +4,7 @@ import discord from discord.ext.commands import Bot -from . import enums, log, node, player_manager, utils, errors +from . import enums, log, node, player_manager, errors __all__ = [ "initialize", @@ -344,7 +344,7 @@ def dispatch(op: enums.LavalinkIncomingOp, data, raw_data: dict): return for coro in listeners: - _loop.create_task(coro(*args)).add_done_callback(utils.task_callback_trace) + _loop.create_task(coro(*args)) async def close(bot): diff --git a/lavalink/node.py b/lavalink/node.py index 4112aa9b..1c17d7e4 100644 --- a/lavalink/node.py +++ b/lavalink/node.py @@ -20,12 +20,6 @@ ) from .player_manager import PlayerManager from .rest_api import Track -from .utils import ( - task_callback_exception, - task_callback_debug, - task_callback_verbose, - task_callback_trace, -) from .errors import AbortingNodeConnection, NodeNotReady, NodeNotFound __all__ = [ @@ -347,10 +341,7 @@ async def _multi_try_connect(self, uri): ws_ll_log.debug("Creating Lavalink WS listener.") if self._is_shutdown is False: self._listener_task = self.loop.create_task(self.listener()) - self._listener_task.add_done_callback(task_callback_exception) - self.loop.create_task(self._configure_resume()).add_done_callback( - task_callback_verbose - ) + self.loop.create_task(self._configure_resume()) if self._queue: temp = self._queue.copy() self._queue.clear() @@ -375,7 +366,6 @@ async def listener(self): self.reconnect_task = self.loop.create_task( self._reconnect(self._is_shutdown) ) - self.reconnect_task.add_done_callback(task_callback_debug) return else: ws_ll_log.info("[NODE] | Listener closing: %s", msg.extra) @@ -388,9 +378,7 @@ async def listener(self): ws_ll_log.verbose("[NODE] | Received unknown op: %s", data) else: ws_ll_log.trace("[NODE] | Received known op: %s", data) - self.loop.create_task(self._handle_op(op, data)).add_done_callback( - task_callback_trace - ) + self.loop.create_task(self._handle_op(op, data)) elif msg.type == aiohttp.WSMsgType.ERROR: exc = self._ws.exception() ws_ll_log.warning( @@ -412,7 +400,6 @@ async def listener(self): self.reconnect_task.cancel() self.update_state(NodeState.RECONNECTING) self.reconnect_task = self.loop.create_task(self._reconnect(self._is_shutdown)) - self.reconnect_task.add_done_callback(task_callback_debug) async def _handle_op(self, op: LavalinkIncomingOp, data): if op == LavalinkIncomingOp.EVENT: @@ -459,7 +446,7 @@ async def _reconnect(self, shutdown: bool = False): attempt += 1 if attempt > 10: ws_ll_log.info("[NODE] | Failed reconnection attempt too many times, aborting ...") - asyncio.create_task(self.disconnect()).add_done_callback(task_callback_debug) + asyncio.create_task(self.disconnect()) return try: await self.connect(shutdown=shutdown) @@ -503,9 +490,7 @@ def update_state(self, next_state: NodeState): ws_ll_log.debug("Event loop closed, not notifying state handlers.") return for handler in self._state_handlers: - self.loop.create_task(handler(next_state, old_state)).add_done_callback( - task_callback_trace - ) + self.loop.create_task(handler(next_state, old_state)) def register_state_handler(self, func): if not asyncio.iscoroutinefunction(func): diff --git a/lavalink/utils.py b/lavalink/utils.py index 38884c5c..fa8023de 100644 --- a/lavalink/utils.py +++ b/lavalink/utils.py @@ -1,36 +1,6 @@ -import asyncio -import contextlib - -from .log import log - - def format_time(time): """Formats the given time into HH:MM:SS""" h, r = divmod(time / 1000, 3600) m, s = divmod(r, 60) - return "%02d:%02d:%02d" % (h, m, s) - - -def task_callback_exception(task: asyncio.Task) -> None: - with contextlib.suppress(asyncio.CancelledError, asyncio.InvalidStateError): - if exc := task.exception(): - log.exception("%s raised an Exception", task.get_name(), exc_info=exc) - - -def task_callback_debug(task: asyncio.Task) -> None: - with contextlib.suppress(asyncio.CancelledError, asyncio.InvalidStateError): - if exc := task.exception(): - log.debug("%s raised an Exception", task.get_name(), exc_info=exc) - - -def task_callback_verbose(task: asyncio.Task) -> None: - with contextlib.suppress(asyncio.CancelledError, asyncio.InvalidStateError): - if exc := task.exception(): - log.verbose("%s raised an Exception", task.get_name(), exc_info=exc) - - -def task_callback_trace(task: asyncio.Task) -> None: - with contextlib.suppress(asyncio.CancelledError, asyncio.InvalidStateError): - if exc := task.exception(): - log.trace("%s raised an Exception", task.get_name(), exc_info=exc) + return f"{h:02d}:{m:02d}:{s:02d}"