Skip to content

Conversation

@crimsonknave
Copy link
Collaborator

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.

@crimsonknave crimsonknave requested a review from a team as a code owner October 17, 2025 18:32
Copilot AI review requested due to automatic review settings October 17, 2025 18:32
Copy link
Contributor

Copilot AI left a 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 finally block 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.

@github-actions
Copy link

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  annotated_logger
  __init__.py
  example
  calculator.py
Project Total  

This report was generated by python-coverage-comment-action

@crimsonknave crimsonknave self-assigned this Oct 17, 2025
@crimsonknave crimsonknave merged commit 5d3c405 into main Oct 17, 2025
25 of 26 checks passed
@crimsonknave crimsonknave deleted the memory-buildup branch October 17, 2025 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants