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

Control session and kernel initialization individually per Cell #273

Open
MarcosVn opened this issue Jul 25, 2024 · 1 comment
Open

Control session and kernel initialization individually per Cell #273

MarcosVn opened this issue Jul 25, 2024 · 1 comment

Comments

@MarcosVn
Copy link
Contributor

MarcosVn commented Jul 25, 2024

Problem

  • I am developing a web application that uses multiple <Cell> components.
  • In my case, I would like to control the initial execution to ensure the order of the cells.
  • I am facing the following error, as it seems I might be executing before the session with the individual kernel of each cell is ready:

image

Proposed Solution

  • Move the isKernelAvailable to ICellState, meaning having this control per cell;
  • Stop conditioning isKernelAvailable to when autoStart is true, i.e., set it as soon as the session's initialize is completed

Additional context

I will implement the proposed solution and submit it soon, as it is more important for our use case.
CC: @eric

MarcosVn pushed a commit to MarcosVn/jupyter-ui that referenced this issue Jul 25, 2024
MarcosVn pushed a commit to MarcosVn/jupyter-ui that referenced this issue Jul 25, 2024
MarcosVn pushed a commit to MarcosVn/jupyter-ui that referenced this issue Jul 25, 2024
MarcosVn pushed a commit to MarcosVn/jupyter-ui that referenced this issue Jul 25, 2024
MarcosVn pushed a commit to MarcosVn/jupyter-ui that referenced this issue Jul 25, 2024
@MarcosVn
Copy link
Contributor Author

Hey, @echarles, how are you?

I have submitted a PR for this enhancement. Could you review it when possible, please?
Here is some functional evidence of the change:

controlled-execution.mp4

In this case, I am using the code snippet below in final app to ensure execution in order, based on the state inserted by the flags:
If you agree and could publish a new version with the change, I would be very grateful!

Usage:

const isExecutingRef = useRef(false);
  useEffect(() => {
    if (id) {
      const handleChange = (newState) => {
        if (newState.areAllCellsReady && !isExecutingRef.current) {
          isExecutingRef.current = true;
          cellStore.getState().execute('1');
          cellStore.getState().execute('2');
        }
      };

      // Subscribe to cellStore changes
      const unsubscribe = cellStore.subscribe(handleChange);

      // Cleanup function to unsubscribe on unmount
      return () => {
        unsubscribe();
      };
    }
  }, [id]);

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

No branches or pull requests

1 participant