Skip to content

AWS SageMaker Code Editor + Jupyter Server don't work properly after reconnecting to the Jupyter Session

0

Hi, my goal is to left my Code Editor unattended.

The problem is when I get back to the Jupyter Session, the cell is either:

  1. not responding (if the cell is still processing)

Code example in a cell

i = 0
while True:
    sleep(1)
    print(i)
    i += 1

When the Code Editor reconnect to the Jupyter Session, you only see a moving line and no output

  1. no output (if the cell is already stop working)

Code example in a cell

from time import sleep

i = 0
while True:
    sleep(1)
    print(i)
    i += 1
    if i == 10:
        break

When the Code Editor reconnect to the Jupyter Session, the output is empty

What I've tried:

  1. Follow this re:Post

https://repost.aws/questions/QUFtgKOWo0Q22MvhHdLuOHag/sagemaker-studio-code-editor-refresh-connection-without-losing-changes

Note:

  1. I am unable to connect to http://localhost:8889/tree?token=<token value> But, I am able to connect to http://localhost:8889

asked 2 years ago647 views

1 Answer
0

As discussed here on GitHub, keeping and restoring full output when re-connecting to a session has been an open challenge in JupyterLab itself for many years... And as far as I understand from the linked issue, it's still not been resolved in core jupyter-server: Instead relying on using jupyverse.

I see the same behaviour you describe: Usually if #1 (not responding) then the cell is still running and the results will be available in the kernel eventually once it finishes... It's just a question of how long to wait before giving up, deciding it must've died instead, and restarting the kernel 😓 If #2 (no output) then the cell typically ran so you can access the results in the kernel variables - just can't see the printed outputs / widgets.

My general advice to customers asking about this over the last few years has been that coming up against this is a signal to change working patterns:

  • Notebooks are intended to be interactive environments. If you want to run long-running jobs in repeatable environments, track your experiments, store the logs, and right-size the compute resources for the work being done - then it's a good time to explore running SageMaker training jobs rather than doing everything in the notebook itself. There really are some nice scalability benefits to using the jobs functionality for things not consuming 100% of your attention as they run - and with the @remote decorator it's easier than ever... Don't even have to write a .py script anymore.
  • If really determined to keep everything in notebook, could consider scheduled notebook jobs - which will run the notebook as a standalone processing job
  • If really determined to keep everything in your interactive notebook space, then I guess try substituting print and progress bar outputs for writing outputs to a file: This way you'll be able to open up your file from JupyterLab/Code Editor and see whether new output is still getting saved - even if the UI output gets disconnected and can't reconnect.
AWS
EXPERT

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.