Skip to content

Commit

Permalink
chore: add gc.collect during on_resumed
Browse files Browse the repository at this point in the history
  • Loading branch information
Skelmis committed Jan 18, 2024
1 parent bb9f44b commit ba699cc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions suggestions/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import datetime
import gc
import io
import logging
import math
Expand Down Expand Up @@ -91,6 +92,7 @@ def __init__(self, *args, **kwargs):
"vote",
}
self.converted_prefix_commands: set[str] = {"suggest", "approve", "reject"}
self.gc_lock: asyncio.Lock = asyncio.Lock()

# Sharding info
self.cluster_id: int = kwargs.pop("cluster", 0)
Expand Down Expand Up @@ -142,6 +144,15 @@ async def dispatch_initial_ready(self):
log.info("Startup took: %s", self.get_uptime())
await self.suggestion_emojis.populate_emojis()

async def on_resumed(self):
if self.gc_lock.locked():
return

async with self.gc_lock:
await asyncio.sleep(2.0)
collected = gc.collect()
log.info(f"Garbage collector: collected {collected} objects.")

@property
def total_cluster_count(self) -> int:
return math.ceil(self.total_shards / 10)
Expand Down

0 comments on commit ba699cc

Please sign in to comment.