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

Launch jlab with asynchronous=True #4

Merged
merged 6 commits into from
Jul 20, 2020

Conversation

mnlevy1981
Copy link
Contributor

I think piping the output to a log file is necessary so we can grab the port and token; for now I'm just printing the log file to stdout in a separate run command to show that asynchronous is working correctly.

Fixes #3

@mnlevy1981
Copy link
Contributor Author

I opted to name the Promise object returned from session.run(..., asynchronous=True) because I assume we'll need that at some point to kill the job. It's currently unused, though.

@mnlevy1981
Copy link
Contributor Author

mnlevy1981 commented Jul 16, 2020

@andersy005 I ran into errors the two times I tried to run your script:

$ jupyter-forward start hobart --conda-env jlab
Password:
DEBUG: jlab_exe is of type <class 'invoke.runners.Promise'>

    To access the notebook, open this file in a browser:
        file:///home/mlevy/.local/share/jupyter/runtime/nbserver-34383-open.html
    Or copy and paste one of these URLs:
        http://hobart.cgd.ucar.edu:59583/?token=TOKEN
     or http://127.0.0.1:59583/?token=TOKEN
[I 17:55:39.443 LabApp] 302 GET /?token=TOKEN (128.117.68.33) 0.92ms
[W 17:55:41.626 LabApp] Could not determine jupyterlab build status without nodejs
[C 17:56:51.451 LabApp] received signal 15, stopping
[I 17:56:51.454 LabApp] Shutting down 0 kernels

Note that port=59628 and the contents of the logfile are:

$ cat .jforward.59628
[I 09:46:26.902 LabApp] [nb_conda_kernels] enabled, 2 kernels found
[I 09:46:31.174 LabApp] The port 59628 is already in use, trying another port.
[I 09:46:31.489 LabApp] [jupyter_nbextensions_configurator] enabled 0.4.1
[I 09:46:34.029 LabApp] JupyterLab extension loaded from /project/oce/mlevy/miniconda3/envs/jlab/lib/python3.7/site-packages/jupyterlab
[I 09:46:34.029 LabApp] JupyterLab application directory is /project/oce/mlevy/miniconda3/envs/jlab/share/jupyter/lab
[I 09:46:34.034 LabApp] Serving notebooks from local directory: /home/mlevy
[I 09:46:34.034 LabApp] The Jupyter Notebook is running at:
[I 09:46:34.034 LabApp] http://hobart.cgd.ucar.edu:59629/?token=TOKEN
[I 09:46:34.034 LabApp]  or http://127.0.0.1:59629/?token=TOKEN
[I 09:46:34.034 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 09:46:34.057 LabApp]

    To access the notebook, open this file in a browser:
        file:///home/mlevy/.local/share/jupyter/runtime/nbserver-51699-open.html
    Or copy and paste one of these URLs:
        http://hobart.cgd.ucar.edu:59629/?token=TOKEN
     or http://127.0.0.1:59629/?token=TOKEN

The process was still running on hobart, but I couldn't access it via port 59629. After killing that process, I tried specifying a port:

$ jupyter-forward start hobart --conda-env jlab --port 8899
Password:
DEBUG: jlab_exe is of type <class 'invoke.runners.Promise'>
tail: cannot open ‘/home/mlevy/.jforward.8899’ for reading: No such file or directory
Traceback (most recent call last):
  File "/Users/mlevy/miniconda3/envs/jupyter_forward/bin/jupyter-forward", line 33, in <module>
    sys.exit(load_entry_point('jupyter-forward', 'console_scripts', 'jupyter-forward')())
  File "/Users/mlevy/NO_BACKUP/codes/jupyter-forward/jupyter_forward/core.py", line 117, in main
    typer.run(app())
  File "/Users/mlevy/miniconda3/envs/jupyter_forward/lib/python3.7/site-packages/typer/main.py", line 214, in __call__
    return get_command(self)(*args, **kwargs)
  File "/Users/mlevy/miniconda3/envs/jupyter_forward/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/mlevy/miniconda3/envs/jupyter_forward/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/mlevy/miniconda3/envs/jupyter_forward/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/mlevy/miniconda3/envs/jupyter_forward/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/mlevy/miniconda3/envs/jupyter_forward/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/mlevy/miniconda3/envs/jupyter_forward/lib/python3.7/site-packages/typer/main.py", line 497, in wrapper
    return callback(**use_params)  # type: ignore
  File "/Users/mlevy/NO_BACKUP/codes/jupyter-forward/jupyter_forward/core.py", line 94, in start
    result = session.run(f'tail {logfile}', hide='out')
  File "<decorator-gen-3>", line 2, in run
  File "/Users/mlevy/miniconda3/envs/jupyter_forward/lib/python3.7/site-packages/fabric/connection.py", line 30, in opens
    return method(self, *args, **kwargs)
  File "/Users/mlevy/miniconda3/envs/jupyter_forward/lib/python3.7/site-packages/fabric/connection.py", line 721, in run
    return self._run(self._remote_runner(), command, **kwargs)
  File "/Users/mlevy/miniconda3/envs/jupyter_forward/lib/python3.7/site-packages/invoke/context.py", line 101, in _run
    return runner.run(command, **kwargs)
  File "/Users/mlevy/miniconda3/envs/jupyter_forward/lib/python3.7/site-packages/invoke/runners.py", line 363, in run
    return self._run_body(command, **kwargs)
  File "/Users/mlevy/miniconda3/envs/jupyter_forward/lib/python3.7/site-packages/invoke/runners.py", line 422, in _run_body
    return self.make_promise() if self._asynchronous else self._finish()
  File "/Users/mlevy/miniconda3/envs/jupyter_forward/lib/python3.7/site-packages/invoke/runners.py", line 489, in _finish
    raise UnexpectedExit(result)
invoke.exceptions.UnexpectedExit: Encountered a bad command exit code!

Command: 'tail ~/.jforward.8899'

Exit code: 1

Stdout:



Stderr: already printed

That's the error I was getting when I put the 1 second sleep in, and I'm surprised your while statement didn't prevent it. I'm about to push a commit to address the second error, not sure what to make of the first. One possibility is that I forgot to delete the old logfile, and the tail command picked up the old file before the new one was generated?

In that case, allow the UnexpectedExit exception
@mnlevy1981
Copy link
Contributor Author

mnlevy1981 commented Jul 16, 2020

7bf6b0c resolves the second error I was seeing:

$ jupyter-forward start hobart --conda-env jlab --port 8899
Password:
DEBUG: jlab_exe is of type <class 'invoke.runners.Promise'>
tail: cannot open ‘/home/mlevy/.jforward.8899’ for reading: No such file or directory
Trying to access ~/.jforward.8899 on hobart again...
[I 10:04:20.098 LabApp] http://hobart.cgd.ucar.edu:8899/?token=TOKEN
[I 10:04:20.098 LabApp]  or http://127.0.0.1:8899/?token=TOKEN
[I 10:04:20.098 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 10:04:20.106 LabApp]

    To access the notebook, open this file in a browser:
        file:///home/mlevy/.local/share/jupyter/runtime/nbserver-56388-open.html
    Or copy and paste one of these URLs:
        http://hobart.cgd.ucar.edu:8899/?token=TOKEN
     or http://127.0.0.1:8899/?token=TOKEN

jupyter_forward/core.py Outdated Show resolved Hide resolved
There were instances where an old copy of logfile was picked up by tail and
then the wrong information was printed to stdout
Fallback is to use $HOME, otherwise use '~'
Copy link
Member

@andersy005 andersy005 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, @mnlevy1981 ! I am going to merge it. If there's anything missing, we can revisit in a separate PR.

@andersy005 andersy005 merged commit 9b8f463 into ncar-xdev:master Jul 20, 2020
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

Successfully merging this pull request may close these issues.

Launch jupyter lab asynchronously
2 participants