def run_inference_process(in_outs: Dict, generation, timeout, debug, return_output=False):
    """
    Modified from `check_correctness` to obtain the inference results.
    :param in_outs:
    :param generation:
    :param timeout:
    :param debug:
    :param return_output:
    :return:
    """

    def _temp_run(problem, generation, debug, result, return_output):
        try:
            if debug:
                print(f"Running test for problem: {problem}")
            result.append(run_inference(in_outs=in_outs, test=generation, debug=debug, return_output=return_output))
            # Useful for debugging the multiprocessing.
            # result.append(run_test(problem=problem, test=generation, debug=debug))
            if debug:
                print(f"Test completed with result: {result}")
        except Exception as e:
            if debug:
                print(f"===================================================================== Error in _temp_run: {e}")

    manager = multiprocessing.Manager()
    result = manager.list()
    p = multiprocessing.Process(target=_temp_run, args=(in_outs, generation, debug, result, return_output))
    p.start()
    p.join(timeout=timeout + 1)
    if p.is_alive():
        if debug:
            print(f"Process is still alive. Killing the process.")
        p.kill()
        # parent = psutil.Process(p.pid)
        # for child in parent.children(recursive=True):
        #     child.kill()
        # parent.kill()
    if not result:
        # Remark: ideally we would consider that all tests failed but we can't access number of tests here easily
        # so we use 21=the average number of tests for a smaple in the test split instead
        avg_number_tests = 21
        if return_output:
            result = [([-1] * avg_number_tests, [None] * avg_number_tests, [None] * avg_number_tests)]
        else:
            result = [[-1] * avg_number_tests]
        if debug:
            print(f"Global timeout occurred, returning default result.")
    if debug:
        print(f"Final result: {result}")
    return result[0]

    Modified from `check_correctness` to obtain the inference results.
    :param in_outs:
    :param generation:
    :param timeout:
    :param debug:
    :param return_output:
    :return:
    
PFPO/scripts/apps/utils_execute.py