While a lambda is still processing (archive unpacking etc), the lambda state should be set to "Pending" (currently "Active") and invocations to that lambda should fail (currently, it can end up in a inconsistent state in this case, like lambdas being executed without layers).

Lambda state should reflect the current internal state, and invocations should fail if not active.
env_vars_before = lambda_executors.LambdaExecutorLocal.set_default_env_variables()
            try:
                handler_module = load_source(lambda_id, lambda_file)
                module_vars = handler_module.__dict__
            finally:
                lambda_executors.LambdaExecutorLocal.reset_default_env_variables(env_vars_before)
                
                
                
                
                post_sys_modules_keys = set(sys.modules.keys())
                for key in post_sys_modules_keys:
                    if key not in pre_sys_modules_keys:
                        sys.modules.pop(key)
        except Exception as e:
            LOG.error("Unable to exec: %s %s", script, traceback.format_exc())
            raise e
        finally:
            if lambda_cwd or lambda_env:
                if lambda_cwd:
                    os.chdir(previous_cwd)
                    sys.path.pop(0)
                if lambda_env:
                    os.environ = previous_env
        return module_vars[handler_function]
    lock = EXEC_MUTEX if lambda_cwd or lambda_env else empty_context_manager()
    with lock:
        return _do_exec_lambda_code()
def get_handler_function_from_name(handler_name, runtime=None):