mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-14 03:34:23 +00:00
First version to merge
This commit is contained in:
33
core/base.py
33
core/base.py
@@ -452,6 +452,39 @@ class Base:
|
||||
except AssertionError as ae:
|
||||
self.logs.error(f'{ae}')
|
||||
|
||||
def is_thread_alive(self, thread_name: str) -> bool:
|
||||
"""Check if the thread is still running! using the is_alive method of Threads.
|
||||
|
||||
Args:
|
||||
thread_name (str): The thread name
|
||||
|
||||
Returns:
|
||||
bool: True if is alive
|
||||
"""
|
||||
for thread in self.running_threads:
|
||||
if thread.name.lower() == thread_name.lower():
|
||||
if thread.is_alive():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
return False
|
||||
|
||||
def is_thread_exist(self, thread_name: str) -> bool:
|
||||
"""Check if the thread exist in the local var (running_threads)
|
||||
|
||||
Args:
|
||||
thread_name (str): The thread name
|
||||
|
||||
Returns:
|
||||
bool: True if the thread exist
|
||||
"""
|
||||
for thread in self.running_threads:
|
||||
if thread.name.lower() == thread_name.lower():
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def thread_count(self, thread_name: str) -> int:
|
||||
"""This method return the number of existing threads
|
||||
currently running or not running
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'''
|
||||
Main utils library.
|
||||
'''
|
||||
import gc
|
||||
from pathlib import Path
|
||||
from re import sub
|
||||
from typing import Literal, Optional, Any
|
||||
@@ -50,6 +51,25 @@ def get_datetime() -> datetime:
|
||||
"""
|
||||
return datetime.now()
|
||||
|
||||
def run_python_garbage_collector() -> int:
|
||||
"""Run Python garbage collector
|
||||
|
||||
Returns:
|
||||
int: The number of unreachable objects is returned.
|
||||
"""
|
||||
return gc.collect()
|
||||
|
||||
def get_number_gc_objects(your_object_to_count: Optional[Any] = None) -> int:
|
||||
"""Get The number of objects tracked by the collector (excluding the list returned).
|
||||
|
||||
Returns:
|
||||
int: Number of tracked objects by the collector
|
||||
"""
|
||||
if your_object_to_count is None:
|
||||
return len(gc.get_objects())
|
||||
|
||||
return sum(1 for obj in gc.get_objects() if isinstance(obj, your_object_to_count))
|
||||
|
||||
def generate_random_string(lenght: int) -> str:
|
||||
"""Retourn une chaîne aléatoire en fonction de la longueur spécifiée.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user