fix(resource): defer log_processor_usages to keep import side-effect-free (todo #157)#261
Open
ywatanabe1989 wants to merge 1 commit intodevelopfrom
Open
fix(resource): defer log_processor_usages to keep import side-effect-free (todo #157)#261ywatanabe1989 wants to merge 1 commit intodevelopfrom
ywatanabe1989 wants to merge 1 commit intodevelopfrom
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scitex.resourcewas eagerly pulling thescitex.io → scitex_io → scitex_devchain via_log_processor_usages, which historically carried dashboard / Flask machinery and risked spawning a listener on:5000at import time.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.log_processor_usagesandmainto PEP 562 lazy attributes; eager imports now stop at the lightweightpsutil/scitex.strspec probes.Test plan
tests/scitex/resource/test_import_no_side_effect.py(3 tests, all subprocess-isolated):test_import_does_not_start_dashboard— no listener on:5000afterfrom scitex.resource import get_specstest_import_does_not_pull_heavy_io_chain—scitex.io/scitex_io/scitex_devare NOT insys.modulesafter the importtest_log_processor_usages_still_accessible_lazily— public API still resolves on demandtests/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_usagesandscitex.resource.maincontinue to work — they just defer the heavy import chain until first access.Refs: https://github.com/ywatanabe1989/todo/issues/157
🤖 Generated with Claude Code