How to trigger env variable change on kernel change?

I am using JupyterLab notebooks in JupyterHub multi user environment.
I would like to set up some environment variable dynamically based on what kernel is chosen by the user in the active notebook. Imagine this variable could be a virtualenv name that gets switched from “kernel_A” to “kernel_B” whenever a user changes “kernel_A” to “kernel_B” in their current notebook.
Has anyone come up with a smart solution how to do it?

There are a couple of suggestions on this forum:

1 Like