Skip to content

Conversation

@RonShakutai
Copy link
Collaborator

Change Description

Defer DeviceDetector creation until first use to avoid unnecessary GPU detection at import time.

Issue reference

Fixes #XX

Checklist

  • I have reviewed the contribution guidelines
  • I have signed the CLA (if required)
  • My code includes unit tests
  • All unit tests and lint checks pass locally
  • My PR contains documentation updates / additions if required

@RonShakutai RonShakutai requested a review from omri374 January 12, 2026 09:55
@github-actions
Copy link

Coverage report (presidio-anonymizer)

This PR does not seem to contain any modification to coverable code.

@github-actions
Copy link

Coverage report (presidio-structured)

This PR does not seem to contain any modification to coverable code.

@github-actions
Copy link

Coverage report (presidio-cli)

This PR does not seem to contain any modification to coverable code.

@github-actions
Copy link

Coverage report (presidio-image-redactor)

This PR does not seem to contain any modification to coverable code.

@github-actions
Copy link

github-actions bot commented Jan 12, 2026

Coverage report (presidio-analyzer)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  presidio-analyzer/presidio_analyzer/nlp_engine
  device_detector.py
Project Total  

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

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 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

@SharonHart SharonHart merged commit 7850688 into main Jan 15, 2026
34 checks passed
@SharonHart SharonHart deleted the ronshakutai/fix-lazy-creation-device-detector branch January 15, 2026 10:02
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.

4 participants