-
Notifications
You must be signed in to change notification settings - Fork 3
Clean up loggers in root manager's loggerDict to prevent memory buildup #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a memory leak issue where decorated functions left persistent logger entries in logging.root.manager.loggerDict, causing memory buildup over time in long-running processes or applications with many function calls.
- Adds logger cleanup in a
finallyblock to ensure loggers are removed even if exceptions occur - Introduces memory leak tests to verify the fix works correctly
- Updates development dependencies to include pytest-memray for memory testing
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| annotated_logger/init.py | Adds logger cleanup logic in finally block and updates version number |
| test/test_memory.py | New test file to verify memory leak prevention and logger cleanup |
| requirements/requirements-dev.txt | Adds pytest-memray and related dependencies for memory testing |
| pyproject.toml | Adds pytest-memray to development dependencies |
| example/calculator.py | Removes commented code line |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
This PR fixes a memory "leak", where every decorated function left a logger in the
logging.root.manager.loggerDict. Any process that ran for long enough or made lots of calls to annotated methods would start to see memory build up. We now remove the logger for the decorated function in a finally so it's removed regardless of if the function raised an exception.