def run_as_another_namespace(
    pid,
    namespaces,
    function,
    *args,
    **kwargs
):
    hack_to_pre_load_modules()

    context = ProcessContext(pid, namespaces)
    context.attach()
    queue = multiprocessing.Queue(2 ** 15)

    try:
        child_process = multiprocessing.Process(
            name='crawler-%s' %
            pid, target=function_wrapper, args=(
                queue, function, args), kwargs=kwargs)
        child_process.start()
    except __HOLE__:
        queue.close()
        raise CrawlError()

    child_exception = None
    try:
        (result, child_exception) = queue.get(timeout=IN_CONTAINER_TIMEOUT)
    except Queue.Empty:
        child_exception = CrawlTimeoutError()
    except Exception:
        result = None

    if child_exception:
        result = None

    child_process.join(IN_CONTAINER_TIMEOUT)

    # The join failed and the process might still be alive

    if child_process.is_alive():
        errmsg = ('Timed out waiting for process %d to exit.' %
                  child_process.pid)
        queue.close()
        os.kill(child_process.pid, 9)
        context.detach()
        logger.error(errmsg)
        raise CrawlTimeoutError(errmsg)

    context.detach()

    if result is None:
        if child_exception:
            raise child_exception
        raise CrawlError('Unknown crawl error.')
    return result
dataset/ETHPy150Open cloudviz/agentless-system-crawler/crawler/namespace.py/run_as_another_namespace