-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from lsst-sqre/tickets/DM-34864
DM-34864: Harden JupyterLab lifecycle handling
- Loading branch information
Showing
11 changed files
with
473 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,9 @@ jobs: | |
uses: pre-commit/[email protected] | ||
|
||
- name: Install tox | ||
run: pip install tox | ||
run: | | ||
pip install -U pip | ||
pip install tox | ||
- name: Cache tox environments | ||
id: cache-tox | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
__all__ = ["ping", "nbexec", "run_python"] | ||
__all__ = ["ping", "nbexec", "run_python", "keep_alive"] | ||
|
||
from .keepalive import keep_alive | ||
from .nbexec import nbexec | ||
from .ping import ping | ||
from .runpython import run_python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Execute Python in the JupyterLab kernel to prevent it from being culled.""" | ||
|
||
from __future__ import annotations | ||
|
||
import sys | ||
from typing import Any, Dict | ||
|
||
from noteburst.jupyterclient.jupyterlab import JupyterError | ||
|
||
|
||
async def keep_alive(ctx: Dict[Any, Any]) -> str: | ||
"""Execute Python code in a JupyterLab pod with a specific Jupyter kernel. | ||
Parameters | ||
---------- | ||
ctx | ||
Arq worker context. | ||
Returns | ||
------- | ||
result : str | ||
The standard-out | ||
""" | ||
logger = ctx["logger"].bind(task="keep_alive") | ||
logger.info("Running keep_alive") | ||
|
||
jupyter_client = ctx["jupyter_client"] | ||
try: | ||
async with jupyter_client.open_lab_session( | ||
kernel_name="LSST" | ||
) as session: | ||
await session.run_python("print('alive')") | ||
except JupyterError as e: | ||
logger.error("keep_alive error", jupyter_status=e.status) | ||
if e.status >= 400 and e.status < 500: | ||
logger.error( | ||
"Authentication error to Jupyter. Forcing worker shutdown", | ||
jupyter_status=e.status, | ||
) | ||
sys.exit("400 class error from Jupyter") | ||
|
||
return "alive" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters