code: def _run_on(
      runner: ThreadedRunner,
      iterate: bool,
      exceptions: list[type[BaseException]],
  ):
      try:
          gen = runner.run()
          if iterate:
              for _ in gen:
                  time.sleep(random.random())
      except Exception as e:
          exceptions.append(e.__class__)
  
imports: from __future__ import annotations
  import random
  import threading
  import time
  from threading import Thread
  from datalad.tests.utils_pytest import assert_raises
  from ..coreprotocols import StdOutCapture
  from ..nonasyncrunner import ThreadedRunner
  from ..protocol import GeneratorMixIn, WitlessProtocol
  from .utils import py2cmd
label_desc: Use image node_id 2 for calling a global function with example usage: _run_on(runner, iterate, exceptions) without return types