diff --git a/jupyter_client/provisioning/local_provisioner.py b/jupyter_client/provisioning/local_provisioner.py index 8abc1b84..f9bae5ff 100644 --- a/jupyter_client/provisioning/local_provisioner.py +++ b/jupyter_client/provisioning/local_provisioner.py @@ -186,8 +186,9 @@ async def pre_launch(self, **kwargs: Any) -> Dict[str, Any]: km.hb_port = lpc.find_available_port(km.ip) km.control_port = lpc.find_available_port(km.ip) self.ports_cached = True - - km.write_connection_file(jupyter_session=kwargs['env'].get("JPY_SESSION_NAME", "")) + if 'env' in kwargs: + jupyter_session = kwargs['env'].get("JPY_SESSION_NAME", "") + km.write_connection_file(jupyter_session=jupyter_session) self.connection_info = km.get_connection_info() kernel_cmd = km.format_kernel_cmd(