Skip to content

Remove use of time.sleep in thread management - #23

Open
dosaboy wants to merge 1 commit into
mainfrom
remove-sleeps
Open

dosaboy wants to merge 1 commit into
mainfrom
remove-sleeps

Conversation

@dosaboy

@dosaboy dosaboy commented Nov 21, 2026

Copy link
Copy Markdown
Owner

No description provided.

@dosaboy
dosaboy force-pushed the remove-sleeps branch 2 times, most recently from 54cd1ca to b634b66 Compare November 24, 2026 21:58
@dosaboy
dosaboy requested a balanced review from Copilot November 24, 2026 22:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Per-line timing runs even when debug logging is disabled, adding unnecessary hot-path overhead that can substantially reduce search throughput.

1 open issue
What changed in this PR

This PR reduces sleep-based polling in search worker management and adds per-line timing diagnostics.

Changes:

  • Use event waits and blocking queue reads for progress logging and result collection.
  • Simplify final result draining and target executor-owned workers during cleanup.
  • Extract line-search logic and report average chunk maxima and maximum line-search duration.
File Description
searchkit/​task.py Extracts line-search logic and adds timing diagnostics.
searchkit/​search.py Replaces sleep-based polling and revises result draining and worker cleanup.

Review effort: Balanced

Comment thread searchkit/task.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new timeout break can let FileSearcher.run() report success with missing matches when result enqueue retries fail, so it must raise FileSearchException instead.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread searchkit/search.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Focused tests are missing to verify that queue.Empty raises FileSearchTimeout without indefinite retries and that successful draining reaches the expected result count.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread searchkit/search.py Resolved
@dosaboy
dosaboy force-pushed the remove-sleeps branch 2 times, most recently from de25184 to 1658d0f Compare November 24, 2026 23:42
@dosaboy
dosaboy requested a balanced review from Copilot November 24, 2026 23:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical cleanup gap lets FileSearchTimeout bypass forced worker termination, so ProcessPoolExecutor shutdown can still hang on stuck workers instead of propagating the timeout.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread searchkit/search.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The review has no active issues concerning the parallel-search management and worker-cleanup changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@dosaboy dosaboy changed the title Reduce use of sleep in thread management Remove use of time.sleep in thread management Nov 25, 2026
@dosaboy
dosaboy requested a balanced review from Copilot November 25, 2026 09:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An exception from future.result() can stop the results collector while workers are still running, allowing the bounded queue to fill, delaying error propagation, and skipping worker cleanup.

1 open issue

Review effort: Balanced

Comment thread searchkit/search.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The timing code uses an adjustable wall clock that can distort elapsed measurements, and its DEBUG-only aggregation lacks deterministic tests for timing output, search-result parity, and the 100,000-line chunk boundary.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread searchkit/task.py Resolved
Comment thread searchkit/task.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The search test fails in the supported DEBUG logging mode because the timing path compares a mocked perf_counter() result with a number, raising a TypeError.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread tests/unit/test_search.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The test assertion can pass solely from unconditional cleanup in the finally block, so it does not verify the new exception-path worker cleanup.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread tests/unit/test_search.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The completion message in searchkit/task.py is missing a closing parenthesis after ms, leaving the diagnostic output malformed.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread searchkit/task.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The failure tests do not cover a worker abruptly exiting while holding the store lock, leaving executor cleanup, thread shutdown, and subsequent search recovery unverified.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread searchkit/search.py Resolved
@dosaboy
dosaboy force-pushed the remove-sleeps branch 2 times, most recently from b0e970f to 513e1b8 Compare November 25, 2026 20:53
@dosaboy
dosaboy requested a balanced review from Copilot November 25, 2026 20:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cleanup can SIGKILL unrelated multiprocessing children, including another search’s Manager, because it selects all children created after a snapshot rather than only this executor’s workers.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread searchkit/search.py Resolved
Removes use of time.sleep() in threads and replaces
with event.wait(). Also uses ProcessPoolExecutor to
clean up processes on termination and adds timing
information for searches to logs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the background-thread and parallel-search cleanup changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

2 participants