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

Is request-scoped kernel isolation possible? #281

Open
mattmutt opened this issue Jul 30, 2024 · 2 comments
Open

Is request-scoped kernel isolation possible? #281

mattmutt opened this issue Jul 30, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@mattmutt
Copy link

mattmutt commented Jul 30, 2024

Hi @echarles , great open source tools from datalayer for a foundation to make Jupyter work with React.

I was looking for guidance or source code pointers to using the React components or datalayer wrapper classes to make a series of input blocks use different kernel processes behind the scenes. I realize this is opposite of the how notebooks work ( 1 kernel for the entire collection of related cells ), but I need isolation to avoid variables and state from being shared.

Problem

I can easily execute all these blocks just fine using kernel.requestExecute() programmatically, but the variables from other blocks are shared, causing problems.

Suggested Improvement

Any further documentation or links of how to use datalayer to invoke the kernel with isolation.

I built a visual demo using many of the datalayer foundation classes, but could not figure out an easy way to have separate kernel processes started for each of the areas. That means the variables are all global, which is undesired.

My example does not use a Notebook concept, but rather experiments with two approaches. A basic Jupyter API combined with a little handwritten React and another that uses the familiar datalayer React Cell component, which looks nicer due to the CodeMirror formatting.

kernel-execution-blocks

@mattmutt mattmutt added the documentation Improvements or additions to documentation label Jul 30, 2024
@echarles
Copy link
Member

Hi @mattmutt The Cell component has a Kernel props, so your use case is supported today. You would have to create the Kernel object in code and create the Cell component passing the kernel you want.

Maybe we need a easier factory, but this is how you would do

const { kernelManager, serviceManager } = useJupyter();
const kernel = new Kernel({
        kernelManager,
        kernelName: 'python',
        kernelSpecName: 'python',
        kernelType: 'notebook',
        kernelspecsManager: serviceManager.kernelspecs,
        sessionManager: serviceManager.sessions,
});

@echarles
Copy link
Member

PS: Actually working on a fix to ensure you can create different kernels (for now, we optimize based on a cookie to ensure there is only one kernel).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants