code: def test_file_number_activity_detection() -> None:
      # Expect an output queue that just has the process exit notification.
      # empty output queue without active threads
      # waits for the process and progresses the generator state
      # to `_ResultGenerator.GeneratorState.process_exited`.
      class TestFNADProtocol(GeneratorMixIn, NoCapture):
          def __init__(self) -> None:
              GeneratorMixIn.__init__(self)
              NoCapture.__init__(self)
  
          def process_exited(self) -> None:
              self.send_result(3)
  
          def connection_lost(
              self, exc: Optional[BaseException]
          ) -> None:
              self.send_result(4)
  
      wl_runner = WitlessRunner()
      result_generator = wl_runner.run(
          cmd=["echo", "a"], protocol=TestFNADProtocol
      )
      assert isinstance(result_generator, _ResultGenerator)
  
      runner = result_generator.runner
      output_queue = runner.output_queue
      assert len(result_generator.runner.active_file_numbers) == 1
      while runner.should_continue():
          runner.process_queue()
  
      # Expect process exited and connection lost to be called.
      assert_equal(result_generator.send(None), 3)
      assert_equal(result_generator.send(None), 4)
      assert_raises(StopIteration, result_generator.send, None)
  
imports: from __future__ import annotations
  import sys
  from queue import Queue
  from typing import Any, Optional
  from datalad.runner.coreprotocols import NoCapture, StdOutErrCapture
  from datalad.runner.nonasyncrunner import _ResultGenerator, run_command
  from datalad.runner.protocol import GeneratorMixIn
  from datalad.tests.utils_pytest import assert_equal, assert_raises
  from ..exception import CommandError
  from ..runner import WitlessRunner
  from .utils import py2cmd
label_desc: Use image node_id 4 for calling a global function with example usage: test_file_number_activity_detection() without return types