Skip to content

Improve threading termination and queue handling#3094

Merged
MMathisLab merged 3 commits intomainfrom
maxim/preprocessing_thread_no_timeout
Sep 18, 2025
Merged

Improve threading termination and queue handling#3094
MMathisLab merged 3 commits intomainfrom
maxim/preprocessing_thread_no_timeout

Conversation

@maximpavliv
Copy link
Copy Markdown
Contributor

@maximpavliv maximpavliv commented Sep 15, 2025

This Pull Request improves the robustness of the multithreading in the inference pipeline.

Changes:

  • Introduces _safe_put and _safe_get helper methods to handle Queue operations safely.
    • Queue operations no longer use a timeout.
    • The producer and consumer respond to a shared _stop_event, ensuring proper shutdown even if one thread crashes or the user interrupts execution (e.g., Ctrl-C).
  • Solves rare queue.Full errors that could occur during model cold start or if the consumer is temporarily slow (reported here, happened to me on rare occasions as well).
  • Ensures that both leftover batches and the sentinel (None) are enqueued safely without risk of blocking.
  • Maintains batch order and correct exception propagation between threads.

Impact:

  • Cleaner and more predictable shutdown of preprocessing and inference threads.
  • Queue-related deadlocks are prevented.
  • Users should no longer encounter queue.Full errors during asynchronous inference, even with large models or slower hardware.

@maximpavliv maximpavliv added the WORK IN PROGRESS! developers are currently working on this feature... stay tuned. label Sep 16, 2025
@maximpavliv maximpavliv changed the title Fix queue.Full errors by blocking producer during model warm-up [WIP] Fix queue.Full errors by blocking producer during model warm-up Sep 16, 2025
@maximpavliv maximpavliv force-pushed the maxim/preprocessing_thread_no_timeout branch from c9f16fb to 7a7a9ff Compare September 16, 2025 14:50
@maximpavliv maximpavliv removed the WORK IN PROGRESS! developers are currently working on this feature... stay tuned. label Sep 16, 2025
@maximpavliv maximpavliv changed the title [WIP] Fix queue.Full errors by blocking producer during model warm-up Improve threading termination and queue handling Sep 16, 2025
@arashsm79
Copy link
Copy Markdown
Contributor

Thanks for this.
Ran inference on some videos using this PR. It is a lot easier to exit out of and interrupt the process now.

LGTM.

@MMathisLab MMathisLab merged commit b788dc2 into main Sep 18, 2025
5 checks passed
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.

3 participants