def _apply_pipes(
    ensure_doc: Callable[[Union[str, Doc, bytes], _AnyContext], Doc],
    pipes: Iterable[Callable[..., Iterator[Doc]]],
    receiver,
    sender,
    underscore_state: Tuple[dict, dict, dict],
) -> None:
    """Worker for Language.pipe

    ensure_doc (Callable[[Union[str, Doc]], Doc]): Function to create Doc from text
        or raise an error if the input is neither a Doc nor a string.
    pipes (Iterable[Pipe]): The components to apply.
    receiver (multiprocessing.Connection): Pipe to receive text. Usually
        created by `multiprocessing.Pipe()`
    sender (multiprocessing.Connection): Pipe to send doc. Usually created by
        `multiprocessing.Pipe()`
    underscore_state (Tuple[dict, dict, dict]): The data in the Underscore class
        of the parent.
    """
    Underscore.load_state(underscore_state)
    while True:
        try:
            texts_with_ctx = receiver.get()

            # Stop working if we encounter the end-of-work sentinel.
            if isinstance(texts_with_ctx, _WorkDoneSentinel):
                sender.close()
                receiver.close()
                return

            docs = (
                ensure_doc(doc_like, context) for doc_like, context in texts_with_ctx
            )
            for pipe in pipes:
                docs = pipe(docs)  # type: ignore[arg-type, assignment]
            # Connection does not accept unpickable objects, so send list.
            byte_docs = [(doc.to_bytes(), doc._context, None) for doc in docs]
            padding = [(None, None, None)] * (len(texts_with_ctx) - len(byte_docs))
            data: Sequence[Tuple[Optional[bytes], Optional[Any], Optional[bytes]]] = (
                byte_docs + padding  # type: ignore[operator]
            )
        except Exception:
            error_msg = [(None, None, srsly.msgpack_dumps(traceback.format_exc()))]
            padding = [(None, None, None)] * (len(texts_with_ctx) - 1)
            data = error_msg + padding

        try:
            sender.send(data)
        except BrokenPipeError:
            # Parent has closed the pipe prematurely. This happens when a
            # worker encounters an error and the error handler is set to
            # stop processing.
            sender.close()
            receiver.close()
            return
Worker for Language.pipe

    ensure_doc (Callable[[Union[str, Doc]], Doc]): Function to create Doc from text
        or raise an error if the input is neither a Doc nor a string.
    pipes (Iterable[Pipe]): The components to apply.
    receiver (multiprocessing.Connection): Pipe to receive text. Usually
        created by `multiprocessing.Pipe()`
    sender (multiprocessing.Connection): Pipe to send doc. Usually created by
        `multiprocessing.Pipe()`
    underscore_state (Tuple[dict, dict, dict]): The data in the Underscore class
        of the parent.
    
spacy/language.py