Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to update kernels env in between restart. #987

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions jupyter_client/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,21 @@ def client(self, **kwargs: t.Any) -> BlockingKernelClient:
# Kernel management
# --------------------------------------------------------------------------

def update_env(self, *, env: t.Dict[str, str]) -> None:
"""
Allow to update the environment of a kernel manager.

This will take effect only after kernel restart when the new env is
passed to the new kernel.

This is useful as some of the information of the current kernel reflect
the state of the session that started it, and those session information
(like the attach file path, or name), are mutable.

.. version-added: 8.5
"""
self._launch_args['env'].update(env)

def format_kernel_cmd(self, extra_arguments: t.Optional[t.List[str]] = None) -> t.List[str]:
"""Replace templated args (e.g. {connection_file})"""
extra_arguments = extra_arguments or []
Expand Down
11 changes: 11 additions & 0 deletions jupyter_client/multikernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ def pre_start_kernel(
)
return km, kernel_name, kernel_id

def update_env(self, *, kernel_id: str, env: t.Dict[str, str]) -> None:
"""
Allow to update the environment of the given kernel.

Forward the update env request to the corresponding kernel.

.. version-added: 8.5
"""
if kernel_id in self:
self._kernels[kernel_id].update_env(env)

async def _add_kernel_when_ready(
self, kernel_id: str, km: KernelManager, kernel_awaitable: t.Awaitable
) -> None:
Expand Down
Loading