LMCache/LMCache

[good-first-issue] cleanup: remove duplicate `import time` inside `lmcache/v1/multiprocess/blend_server_v2.py`

Chiusa

#3373 aperta il 23 mag 2026

 (0 commenti) (0 reazioni) (0 assegnatari)Python (1195 fork)user submission
area/lintgood first issuehelp wantedonboarding-2026

Metriche repository

Star
 (8345 stelle)
Metriche merge PR
 (Merge medio 6g 13h) (204 PR mergiate in 30 g)

Descrizione

Background

In lmcache/v1/multiprocess/blend_server_v2.py, the time module is imported twice:

  • L43 — at the top of the file (correct, module-level).
  • L635 — inside a while True: loop in a method body (redundant). This shadows the top-level import, runs an unnecessary sys.modules lookup on every iteration, and violates PEP 8 / ruff E402 ("imports at top of file").
# L43
import time

...

# L635 (inside a hot loop)
            while True:
                found_count = self.storage_manager.query_prefetch_status(handle)
                if found_count is not None:
                    break

                # Standard
                import time          # <-- redundant, please remove

                time.sleep(0.001)

Task

Delete the redundant import time at line 635 (and the now-meaningless # Standard comment right above it). Do not touch anything else. Expected diff: ~3 lines removed, 0 added.

How to fix

  1. Open lmcache/v1/multiprocess/blend_server_v2.py.
  2. Around line 635, remove these two lines:
                    # Standard
                    import time
    
  3. Leave the time.sleep(0.001) call as-is — time is still imported at the top of the file (L43).

How to verify

⚠️ The repo's ruff config does not enable rules that flag duplicate imports across scopes, so ruff check alone is not proof. Use the AST script below — it directly counts how many times the name time is imported in this file.

# 1) Should print exactly: time 1
python - <<'PY'
import ast, pathlib, collections
p = pathlib.Path("lmcache/v1/multiprocess/blend_server_v2.py")
counts = collections.Counter()
for n in ast.walk(ast.parse(p.read_text())):
    if isinstance(n, ast.Import):
        for a in n.names:
            counts[a.asname or a.name.split(".")[0]] += 1
print("time", counts["time"])
PY

# 2) Sanity: formatting and lint still pass.
pre-commit run --all-files

# 3) Smoke: import the module — must not raise.
python -c "import lmcache.v1.multiprocess.blend_server_v2"

Expected output of step (1): time 1. Before this fix it prints time 2.

Out of scope

  • Do not rename variables, refactor the loop, or touch other files.
  • Do not "fix" other duplicate imports in the repo in this PR — there is a separate sub-task per file under the umbrella.

PR checklist (tick before requesting review)

  • Diff is ≤ 3 lines removed, 0 lines added.
  • pre-commit run --all-files passes locally.
  • AST script above prints time 1.
  • python -c "import lmcache.v1.multiprocess.blend_server_v2" works.
  • PR title: cleanup: remove duplicate import time in blend_server_v2
  • PR body contains: Refs #<umbrella> and Closes #<this-issue>.

Refs #3372

Guida contributor