datalayer/jupyter-server-nbmodel

Should code be executed asynchronously in RTC mode?

Closed this issue · 3 comments

Problem

reply = await ensure_async(
client.execute_interactive(
snippet,
output_hook=self._output_hook,
stdin_hook=self._stdin_hook if client.allow_stdin else None,
)
)

I've found that current implementations where cell takes longer to execute can lead to http request timeouts (especially behind some reverse proxies), and it's difficult for the front-end to determine if the request to execute the code was successfully sent.

Proposed Solution

  1. We can simply support asynchronous mode: do execute and safe in an asyncio.Task.
  2. Maybe we need an optimistic lock to prevent racing when concurrent write to the ynotebook.

Additional context

Hey @Wh1isper thanks for testing, actually we cannot switch to asynchronous mode fully to be able to support the input case.

I plan to implement the following logic that will cover that case:

  1. Return 202 with Location to get the execution result when receiving the request
  2. On the result endpoint, return early if an input is needed otherwise return the results

Return 202 with Location to get the execution result when receiving the request

It sounds like we can only perform one code execution operation at a time? Or we will relay on kernel's zmq queue?

@Wh1isper I opened #9 which implements my proposal (it requires the latest version of jupyterlab/jupyter-collaboration#307), if you want to have a look.

The solution I have in mind for stdin does not work. Currently the server is locked on an input request. If you have any idea to work around that. I'll be happy to hear them.