diff --git a/fastembed/parallel_processor.py b/fastembed/parallel_processor.py index ffb3d6ec..36688d87 100644 --- a/fastembed/parallel_processor.py +++ b/fastembed/parallel_processor.py @@ -215,10 +215,14 @@ def semi_ordered_map( # join would wait forever for processes blocked on the input queue. self.emergency_shutdown = True self.join_or_terminate() - # Nothing reads the input pipe anymore, so the feeder thread can be stuck writing to it, - # holding every batch it hasn't sent. Closing our read end fails that write with EPIPE and - # lets the thread exit, same as Queue._terminate_broken() in python 3.12+. - self.input_queue._reader.close() # type: ignore[attr-defined] + # Nothing reads the input pipe anymore, so the feeder thread can be stuck + # writing to it, holding every item it hasn't sent. On POSIX, closing our + # read end fails that write with EPIPE; Windows also needs to cancel the send. + terminate_broken = getattr(self.input_queue, "_terminate_broken", None) + if terminate_broken is not None: + terminate_broken() + else: + self.input_queue._reader.close() # type: ignore[attr-defined] self.input_queue.close() self.output_queue.close() if self.emergency_shutdown: