Skip to content

fix: improve thread safety and execution logging with minimal changes #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2025

Conversation

0xtavian
Copy link
Contributor

@0xtavian 0xtavian commented Apr 17, 2025

✨ Pull Request: Improve Thread Execution and Logging Behavior

Summary

This PR improves thread safety, execution accuracy, and log clarity in Interlace, while preserving the original behavior, structure, and test harness with minimal changes.


✅ What's Changed

threader.py

  • Replaces use of next(task_queue) with a thread-safe queue.Queue to prevent premature thread exits.
  • Moves [THREAD] Added to Queue logging from task generation time to actual execution time (inside each worker thread).
  • Adds OutputHelper to enable consistent, styled terminal output from within threads.
  • Catches task-level exceptions to prevent individual thread crashes.

interlace.py

  • Passes output_helper=output to Pool for use inside threads.
  • Removes redundant [THREAD] ... Added to Queue log from task queue generator.

✅ Why It Matters

  • Prevents thread starvation in long or unstable task batches.
  • Aligns task execution logs with real execution (not pre-queueing).

- Replaces generator-based task queue with thread-safe queue.Queue in threader.py to prevent thread starvation
- Moves '[THREAD] Added to Queue' logging from task generation to execution time
- Integrates OutputHelper into Worker for consistent styled logs
- Preserves original behavior of stderr visibility and test harness
- Updates interlace.py to pass output_helper, removes duplicate logging
- Retains original structure, repeat logic, and test interface to minimize diff
Copy link

@Copilot 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 enhances thread safety and logging clarity by replacing the iterator‐based task queue with a thread-safe queue and by moving the "[THREAD] Added to Queue" message to the actual task execution phase. Key changes include the introduction of queue.Queue in the Pool, the addition of an OutputHelper for consistent styled terminal output, and a revised logging approach in Interlace to preserve output behavior.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Interlace/lib/threader.py Switched to queue.Queue for task management and moved logging inside worker execution.
Interlace/interlace.py Adjusted logging by commenting out early log output and passing output as output_helper.
Comments suppressed due to low confidence (2)

Interlace/lib/threader.py:110

  • [nitpick] The variable 'tasks_count' is derived from the first element of the task_queue iterator; consider renaming it to 'total_tasks' or adding a clarifying comment to indicate that the iterator's first value represents the total number of tasks.
tasks_count = next(task_queue)

Interlace/interlace.py:41

  • Ensure that the 'output' passed as output_helper is an instance of OutputHelper, as expected by the Pool implementation, to maintain consistent logging behavior.
output_helper=output

@prodigysml prodigysml merged commit b9eb99f into codingo:master Apr 19, 2025
1 check failed
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