-
Notifications
You must be signed in to change notification settings - Fork 904
Refactor: lazy initialization for device_detector singleton #1831
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
Refactor: lazy initialization for device_detector singleton #1831
Conversation
Coverage report (presidio-analyzer)Click to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
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 refactors the device_detector singleton initialization from eager (at module import time) to lazy (on first access) using Python's module-level __getattr__ mechanism. This aims to defer expensive GPU detection until the singleton is actually used.
Changes:
- Implemented lazy initialization using module-level
__getattr__to defer device detection - Simplified exception handling in
_detect()method by catching all exceptions in one block - Updated module documentation to reflect lazy initialization pattern
presidio-analyzer/presidio_analyzer/nlp_engine/device_detector.py
Outdated
Show resolved
Hide resolved
…nsformersRecognizer to use it
Change Description
Defer DeviceDetector creation until first use to avoid unnecessary GPU detection at import time.
Issue reference
Fixes #XX
Checklist