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

How to send multiple and consecutive execute_request ? #528

Open
haotianzhu opened this issue Dec 8, 2019 · 8 comments
Open

How to send multiple and consecutive execute_request ? #528

haotianzhu opened this issue Dec 8, 2019 · 8 comments

Comments

@haotianzhu
Copy link

I am trying to send consecutive executable codes to the sage server.
I follow the instructions of sagecell_client.py.
I find that after the code is executed, the socket and session are auto-closed.
Is there a way to stop WebSocket closing after the first code is executed? Or is there any flag to allow the sage server to receive multiple requirements in one channel?

Thanks

@novoselt
Copy link
Member

novoselt commented Dec 9, 2019

This is by design - it is a single request with a single response. What is your use case for multiple requests to a single kernel? Why can't you feed everything at once?

@haotianzhu
Copy link
Author

Something like the colab, multiple cells are executed from top to bottom. My first idea is that each cell will call a single request to an open WebSocket. After every cell is executed, WebSocket is closed.

@novoselt
Copy link
Member

We do support linked cells - do they suit your needs?

@ro70
Copy link

ro70 commented Aug 1, 2021

I am trying something similar with a very naive approach. One click on "evalAll" should trigger all three evaluations.

With the first click on "evalAll", the results 4, 6 and 402 are all written into the first output-div.

With the second, third, ... click on "evalAll" the results are then correctly distributed to the different output-divs (even if I change the value of a or b).

Why does it behave differently with the first click?

Code:

<!doctype html>
<html lang="en">
  <head>
    <script src="https://sagecell.sagemath.org/static/embedded_sagecell.js"></script>
  </head>
  <body>

    <div class="cell" id="0">
      <script type="text/x-sage">
a=2
2*a
      </script>
    </div>
    <div class="cell" id="1">
      <script type="text/x-sage">
b=20
3*a
      </script>
    </div>
    <div class="cell" id="2">
      <script type="text/x-sage">
b^2+a
      </script>
    </div>

    <button type="button" id="evalAll">evalAll</button>

    <script>
      sagecell.makeSagecell({
        inputLocation: '.cell',
        linked: true,
      });

      var evalAll = document.getElementById('evalAll');
      evalAll.addEventListener('click', event => {
        var evalBtns = [].slice.call(document.getElementsByClassName('sagecell_evalButton'));
        evalBtns.forEach(btn => {
          console.log(btn.closest('div.cell').id);
          btn.click();
        });
      });
    </script>
  </body>
</html>

@novoselt
Copy link
Member

novoselt commented Aug 1, 2021

What is the use case? If you want to execute a bunch of code at once - put it in the same cell. If you want to change code of the second cell based on the output of the first one - use linked cells and let the user press the button when needed. There is apparently some race condition with clicking on several buttons automatically. I am not convinced that there is a point in figuring out how to make it work.

@ro70
Copy link

ro70 commented Aug 2, 2021

As a use case, I imagine solving a task with different parts.

E.G.
a) Determine the derivative of f.
b) Determine the derivative of f at the point 1.
c) ...
d) ...

If I can distribute these parts to different (linked) sage cells, I don't need print commands for the output of the results and all results are nicely ordered. I can clearly separate the individual parts of the task.

I'd prefer something like that

f(x)=3*x^2
df(x)=diff(f(x),x)
df(x)
df(1)
...

to this

f(x)=3*x^2
df(x)=diff(f(x),x)
print(df(x))
df(1)
...

@novoselt
Copy link
Member

novoselt commented Aug 2, 2021

Ok, and what is the problem with having the user to execute each of the parts if they are supposed to be interactive? If the user is not supposed to change the code, then it may look even better if you post a printout of a session, with no recomputation on each load.

@ro70
Copy link

ro70 commented Aug 3, 2021

The individual cells should be interactive. If each cell has its evaluation button, all subsequent evaluation buttons must be clicked when a change is made (in the worst case). This is tedious and it is easy to change a cell and forget to click an evaluation button. Then the results in other cells may no longer be correct.

Pupils are to work with the planned interface. It should therefore be as simple as possible.

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

3 participants