code: def run_polling_stderr(
      args: Args,
      *,
      callback: Callable[[str], None],
      check: bool = False,
      env: OsEnviron | None = None,
      **kwargs,
  ) -> CompletedProcess:
      """Run a process like ``ocrmypdf.subprocess.run``, and poll stderr.
  
      Every line of produced by stderr will be forwarded to the callback function.
      The intended use is monitoring progress of subprocesses that output their
      own progress indicators. In addition, each line will be logged if debug
      logging is enabled.
  
      Requires stderr to be opened in text mode for ease of handling errors. In
      addition the expected encoding= and errors= arguments should be set. Note
      that if stdout is already set up, it need not be binary.
      """
      args, env, process_log, text = _fix_process_args(
          args, env, kwargs
      )
      assert text, "Must use text=True"
  
      with Popen(args, env=env, **kwargs) as proc:
          lines = []
          while proc.poll() is None:
              if proc.stderr is None:
                  continue
              for msg in iter(proc.stderr.readline, ""):
                  if process_log.isEnabledFor(logging.DEBUG):
                      process_log.debug(msg.strip())
                  callback(msg)
                  lines.append(msg)
          stderr = "".join(lines)
  
          if check and proc.returncode != 0:
              raise CalledProcessError(
                  proc.returncode, args, output=None, stderr=stderr
              )
          return CompletedProcess(
              args, proc.returncode, None, stderr=stderr
          )
  
imports: from __future__ import annotations
  import logging
  import os
  import re
  import sys
  from collections.abc import Mapping, Sequence
  from contextlib import suppress
  from pathlib import Path
  from subprocess import PIPE, STDOUT, CalledProcessError, CompletedProcess, Popen
  from subprocess import run
  from typing import Callable, Union
  from packaging.version import Version
  from ocrmypdf.exceptions import MissingDependencyError
label_desc: Use image node_id 2 for calling a global function with example usage: run_polling_stderr(args) and returns: CompletedProcess