def _check_subprocesses_number(executor, expected_process_number=None, expected_max_process_number=None, patience=100):
    children_cmdlines = _running_children_with_cmdline(psutil.Process())
    pids_cmdlines = [(c.pid, cmdline) for (c, cmdline) in children_cmdlines]
    children_pids = {pid for (pid, _) in pids_cmdlines}
    if (executor is not None):
        worker_pids = set(executor._processes.keys())
    else:
        worker_pids = children_pids
    if (expected_process_number is not None):
        try:
            assert (len(children_pids) == expected_process_number), pids_cmdlines
            assert (len(worker_pids) == expected_process_number), pids_cmdlines
            assert (worker_pids == children_pids), pids_cmdlines
        except AssertionError:
            if (expected_process_number != 0):
                raise
            for _ in range(patience):
                if (not _running_children_with_cmdline(psutil.Process())):
                    break
                time.sleep(0.1)
            else:
                raise
    if (expected_max_process_number is not None):
        assert (len(children_pids) <= expected_max_process_number), pids_cmdlines
        assert (len(worker_pids) <= expected_max_process_number), pids_cmdlines
def _check_subprocesses_number(executor, expected_process_number=None, expected_max_process_number=None, patience=100):
    children_cmdlines = _running_children_with_cmdline(psutil.Process())
    pids_cmdlines = [(c.pid, cmdline) for (c, cmdline) in children_cmdlines]
    children_pids = {pid for (pid, _) in pids_cmdlines}
    if (executor is not None):
        worker_pids = set(executor._processes.keys())
    else:
        worker_pids = children_pids
    if (expected_process_number is not None):
        try:
            assert (len(children_pids) == expected_process_number), pids_cmdlines
            assert (len(worker_pids) == expected_process_number), pids_cmdlines
            assert (worker_pids == children_pids), pids_cmdlines
        except AssertionError:
            if (expected_process_number != 0):
                raise
            for _ in range(patience):
                if (not _running_children_with_cmdline(psutil.Process())):
                    break
                time.sleep(0.1)
            else:
                raise
    if (expected_max_process_number is not None):
        assert (len(children_pids) <= expected_max_process_number), pids_cmdlines
        assert (len(worker_pids) <= expected_max_process_number), pids_cmdlines