aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-02-15 11:38:27 -0800
committerGravatar MarkKoz <[email protected]>2020-02-15 11:41:36 -0800
commita417c318e6a0e57fa53b9b68572a524e0aa0f729 (patch)
tree672b61a49e1f87017d0528c6ed13036f92f90f61
parentBot: call _recreate() in clear() (diff)
Bot: warn when connector/session not closed when recreating
aiohttp does warn too, but these warnings will provide more immediate feedback.
-rw-r--r--bot/bot.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/bot/bot.py b/bot/bot.py
index 9f48c980c..0287ec925 100644
--- a/bot/bot.py
+++ b/bot/bot.py
@@ -72,7 +72,18 @@ class Bot(commands.Bot):
# Use asyncio for DNS resolution instead of threads so threads aren't spammed.
# Use AF_INET as its socket family to prevent HTTPS related problems both locally
# and in production.
+
+ # Doesn't seem to have any state with regards to being closed, so no need to worry?
self._resolver = aiohttp.AsyncResolver()
+
+ # Does have a closed state. Its __del__ will warn about this, but let's do it immediately.
+ if self._connector and not self._connector._closed:
+ warnings.warn(
+ "The previous connector was not closed; it will remain open and be overwritten",
+ ResourceWarning,
+ stacklevel=2
+ )
+
self._connector = aiohttp.TCPConnector(
resolver=self._resolver,
family=socket.AF_INET,
@@ -82,5 +93,12 @@ class Bot(commands.Bot):
# this connector attribute.
self.http.connector = self._connector
+ if self.http_session and not self.http_session.closed:
+ warnings.warn(
+ "The previous ClientSession was not closed; it will remain open and be overwritten",
+ ResourceWarning,
+ stacklevel=2
+ )
+
self.http_session = aiohttp.ClientSession(connector=self._connector)
self.api_client.recreate(connector=self._connector)