Buckets:

download
raw
1.16 kB
"""Functionality for working with Jupyter."""
from __future__ import annotations
import subprocess
import sys
from pydantic import BaseModel
class Server(BaseModel):
url: str
wdir: str
token: str
def get_servers() -> list[Server]:
out = (
subprocess.check_output(
[sys.executable, "-m", "jupyter", "server", "list"]
)
.decode()
.strip()
.split("\n")
)
resp = []
for line in out:
if line.startswith("http://"):
url, wdir = line.split(" :: ")
token = url.split("?token=")[-1]
resp.append(Server(url=url, wdir=wdir, token=token))
return resp
def start_server(wdir=None, no_browser=False):
"""Start a Jupyter server."""
subprocess.Popen(
[
sys.executable,
"-m",
"jupyter",
"lab",
"-y",
"--no-browser" if no_browser else "",
],
cwd=wdir,
)
def stop_server(url: str):
# Extract the port from the URL
port = url.split(":")[2][:4]
subprocess.call([sys.executable, "-m", "jupyter", "server", "stop", port])

Xet Storage Details

Size:
1.16 kB
·
Xet hash:
4b12fb197ee9185dcb615baa37beb0a94a60b29f009d1257a563693ce44f6e91

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.