Skip to content

fix(resource): defer log_processor_usages to keep import side-effect-free (todo #157)#261

Open
ywatanabe1989 wants to merge 1 commit intodevelopfrom
fix/resource-no-import-side-effect-todo-157
Open

fix(resource): defer log_processor_usages to keep import side-effect-free (todo #157)#261
ywatanabe1989 wants to merge 1 commit intodevelopfrom
fix/resource-no-import-side-effect-todo-157

Conversation

@ywatanabe1989
Copy link
Copy Markdown
Owner

Summary

  • Importing scitex.resource was eagerly pulling the scitex.io → scitex_io → scitex_dev chain via _log_processor_usages, which historically carried dashboard / Flask machinery and risked spawning a listener on :5000 at import time.
  • Sidecars and CLI tools shell out to python -c "from scitex.resource import get_specs; ..." on every metrics tick (see todo fix(rtd): Add deps and mock imports for autodoc #157 for the Orochi sidecar context), so the import path has to stay lightweight and silent.
  • Move log_processor_usages and main to PEP 562 lazy attributes; eager imports now stop at the lightweight psutil / scitex.str spec probes.

Test plan

  • New regression tests at tests/scitex/resource/test_import_no_side_effect.py (3 tests, all subprocess-isolated):
    • test_import_does_not_start_dashboard — no listener on :5000 after from scitex.resource import get_specs
    • test_import_does_not_pull_heavy_io_chainscitex.io / scitex_io / scitex_dev are NOT in sys.modules after the import
    • test_log_processor_usages_still_accessible_lazily — public API still resolves on demand
  • Full tests/scitex/resource/ suite: 129 passed, 1 skipped, 0 failed (3 new + 126 existing).

API note

No public API breakage. from scitex.resource import log_processor_usages and scitex.resource.main continue to work — they just defer the heavy import chain until first access.

Refs: https://github.com/ywatanabe1989/todo/issues/157

🤖 Generated with Claude Code

… chain

Importing scitex.resource was eagerly pulling the scitex.io → scitex_io
→ scitex_dev chain via _log_processor_usages, which historically carried
dashboard / Flask machinery and risked spawning a listener on :5000 at
import time. Sidecars / CLI tools shell out to
`from scitex.resource import get_specs` on every metrics tick, so the
import path must stay lightweight and side-effect-free.

Move log_processor_usages and main to PEP 562 lazy attributes; eager
imports now stop at the lightweight psutil/scitex.str spec probes. The
public API is unchanged — `from scitex.resource import log_processor_usages`
and `scitex.resource.main` still resolve, just on first access.

Adds tests/scitex/resource/test_import_no_side_effect.py with three
regression tests (subprocess-isolated): no listener appears on :5000
after import, no scitex.io / scitex_dev modules are eagerly loaded, and
log_processor_usages remains accessible lazily.

Refs: ywatanabe1989/todo#157

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant