A decorator that automatically clears temporary local variables upon function execution, effectively preventing clutter and mitigating memory leaks.
Project description
mswp, a decorator that clears temporary local variables upon function execution, preventing clutter and mitigating memory leaks
mswp is a Python decorator designed to enhance code cleanliness and mitigate potential memory leaks by automatically clearing temporary local variables after function execution.
Overview
Python functions often create temporary variables for intermediate computations, which can clutter the local namespace and potentially lead to memory leaks if not properly managed. mswp addresses this issue by providing a simple yet powerful decorator that automatically cleans up temporary local variables, ensuring an efficient execution environment.
Installation
You can install mswp via pip:
pip3 install mswp
Usage
To use mswp, simply decorate your functions with @mswp. This ensures that any temporary local variables used within the function are cleared upon completion, promoting code cleanliness and efficient memory usage.
from mswp import clear
@clear
def my_function():
temp_var = 10
# Your code here
return result
In this example, my_function is decorated with @clear, ensuring that any temporary local variables used within it are cleared upon completion.
Parameters
func
: The function to be decorated.
Returns
function
: The decorated function.
Features
-
Automatic Cleanup: mswp automatically clears temporary local variables after function execution, preventing clutter and potential memory leaks.
-
Simplified Syntax: With a simple decorator, mswp streamlines code maintenance and promotes readability.
-
Error Handling: mswp provides robust error handling to ensure reliable execution even in the presence of exceptions.
Citing this project
If you use this code in your research, please use the following BibTeX entry.
@misc{louisbrulenaudet2023,
author = {Louis Brulé Naudet},
title = {mswp, a decorator that automatically clears temporary local variables upon function execution, effectively preventing clutter and mitigating memory leaks},
howpublished = {\url{https://github.com/louisbrulenaudet/mswp}},
year = {2024}
}
Feedback
If you have any feedback, please reach out at louisbrulenaudet@icloud.com.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mswp-1.0.0.tar.gz
.
File metadata
- Download URL: mswp-1.0.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc270354aafddf0c30a917bffb662a58be9d26dd4c42e84a627730899f19a013 |
|
MD5 | ea1fe572c20651f206cc4e63494d48f9 |
|
BLAKE2b-256 | 658e62ee2871e8ed698913f73beb912685609ad39a36fc07713d84ad275b1530 |
File details
Details for the file mswp-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: mswp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5205b05793b9fa9d73e5da3dcbd394ff1fcbb2bfad90efbc4e1b4f66eaea8df |
|
MD5 | 5e876cc2c98a94a8ec2ae64a14f12c74 |
|
BLAKE2b-256 | 1c8f3f94995b3be15a13d2227e69b30cd0436d551c3e24299ad959545cfecbd8 |