Enabled tracemalloc temporary

This commit is contained in:
Joan Cano
2023-08-16 11:40:32 +02:00
parent 8fba7e1473
commit bc71257782
3 changed files with 53 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import walladb
import constants
import account_checker
import time
import tracemalloc
from worker import Worker
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, ForceReply
@@ -439,10 +440,26 @@ async def list_threads(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
await update.message.reply_markdown_v2(helpers.telegram_escape_characters(f"{threads_string}"))
def count_threads():
tracemalloc.start()
time.sleep(10)
while True:
snapshot1 = tracemalloc.take_snapshot()
logging.info(f"=== There are: {threading.active_count()} threads. ===")
time.sleep(60)
snapshot2 = tracemalloc.take_snapshot()
top_stats = snapshot2.compare_to(snapshot1, 'lineno')
logging.info("[ Top 10 differences ]")
for stat in top_stats[:10]:
logging.info(stat)
top_stats = snapshot2.statistics('lineno')
logging.info("[ Top 10 ]")
for stat in top_stats[:10]:
logging.info(stat)
def main()->None:
global SEARCH_THREADS_LIST