code: def test_batched_restart():
      # Expect that the process is restarted after exit.
      bc = BatchedCommand(
          cmd=py2cmd(
              "import os\n"
              "import sys\n"
              "print(os.getpid(), sys.stdin.readline().strip())\n"
          )
      )
  
      # Send four lines
      lines = [f"line-{i}" for i in range(4)]
      responses = [bc(lines[i]).split() for i in range(4)]
      pid_set = set([int(r[0]) for r in responses])
      assert_equal(len(pid_set), 4)
      response_lines = [r[1] for r in responses]
      assert_equal(lines, response_lines)
      bc.close(return_stderr=False)
  
file_path: datalad/datalad/tests/test_cmd.py
imports: import sys
  import unittest.mock
  from subprocess import TimeoutExpired
  import pytest
  from datalad.cmd import BatchedCommand, readline_rstripped
  from datalad.cmd import BatchedCommandError
  from datalad.runner.tests.utils import py2cmd
  from datalad.tests.utils_pytest import assert_equal, assert_is_none, assert_is_not_none, assert_not_equal, assert_true
label_desc: Use image node_id 8 for calling a global function with example usage: test_batched_restart() without return types