Spaces:
Runtime error
Runtime error
| # *************************************************************************** # | |
| # # | |
| # memory.py # | |
| # # | |
| # By: Widium <ebennace@student.42lausanne.ch> # | |
| # Github : https://github.com/widium # | |
| # # | |
| # Created: 2023/05/03 14:12:23 by Widium # | |
| # Updated: 2023/05/03 14:12:23 by Widium # | |
| # # | |
| # **************************************************************************** # | |
| import os | |
| import psutil | |
| def display_memory_available(): | |
| """ | |
| Print the available system memory in gigabytes. | |
| This function retrieves the available memory information and prints it | |
| in gigabytes. | |
| """ | |
| memory_info = psutil.virtual_memory() | |
| available_memory = memory_info.available | |
| gigabytes_memory = available_memory / 1024 ** 3 | |
| print(f"[MEMORY] : Available memory [{gigabytes_memory:.2f}] GB") | |
| def display_memory_usage(): | |
| """Print the current process memory usage in megabytes. | |
| This function retrieves the memory usage of the current process and | |
| prints it in megabytes. | |
| """ | |
| process = psutil.Process(os.getpid()) | |
| mem_info = process.memory_info() | |
| megabytes_memory = mem_info.rss / (1024 ** 2) # Convert bytes to MB | |
| print(f"[MEMORY] : Memory Usage [{megabytes_memory:.2f}] MB") |