mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 11:14:23 +00:00
First version to merge
This commit is contained in:
@@ -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