From 53e4fcc791cc85d4c83fe3e93c52e1de179ba278 Mon Sep 17 00:00:00 2001 From: Yoav Date: Wed, 18 Nov 2026 14:22:41 +0200 Subject: [PATCH] Show Python download progress and allow slow startup --- site/assets/PYTHON-RUNTIME.md | 2 +- site/assets/notebook-lab.js | 7 ++++--- site/assets/python-worker.js | 4 +++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/site/assets/PYTHON-RUNTIME.md b/site/assets/PYTHON-RUNTIME.md index ab19321..e800ef8 100644 --- a/site/assets/PYTHON-RUNTIME.md +++ b/site/assets/PYTHON-RUNTIME.md @@ -18,5 +18,5 @@ prepare_browser.py regenerates that virtual filesystem at build time. The worker runs Python on the learner's device. Source edits are stored in localStorage when available; variables and virtual filesystem state last only -until restart. The controller reapplies the editors on a fresh kernel. +until restart. A fresh Python session uses the saved project files and the current notebook cells. No analytics, accounts, or backend execution are used. diff --git a/site/assets/notebook-lab.js b/site/assets/notebook-lab.js index 4a91b89..c1d9bc9 100644 --- a/site/assets/notebook-lab.js +++ b/site/assets/notebook-lab.js @@ -8,6 +8,7 @@ const filePaths = {helper: 'helpers.py', config: 'config/analysis.toml'}; const baseConfig = '[paths]\ndata = "../data/raw/trials.csv"\noutput = "../results/baseline"\n\n[preprocessing]\nmin_rt_s = 0.2\nmax_rt_s = 2.0\n'; const baseHelper = 'def clean_trials(trials, min_rt_s=0.2, max_rt_s=2.0):\n return trials.loc[trials.reaction_time.between(min_rt_s, max_rt_s)].copy()\n'; const storageKey = 'research-code-notebook-v1'; +const pythonLoadTimeout = 300000; const guide = q('[data-guide-action]'); const feedback = q('[data-guide-feedback]'); const stepPanel = q('#current-step'); @@ -97,7 +98,7 @@ function request(action, values = {}, timeout = 15000) { const id = ++sequence; return new Promise((resolve, reject) => { const timer = setTimeout(() => { - terminate(action === 'init' ? 'Python took too long to load.' : 'Python stopped because the action timed out.'); + terminate(action === 'init' ? 'Python did not finish downloading. Check your connection or run the downloaded project in Jupyter.' : 'Python stopped because the action timed out.'); }, timeout); pending.set(id, {resolve, reject, timer}); worker.postMessage({id, action, ...values}); @@ -125,9 +126,9 @@ async function start() { if (worker === activeWorker) terminate('Python could not load. Reload the page if retrying does not help.'); }; controls(); - message('Loading Python and scientific packages…'); + message('Starting Python…'); const projectFiles = Object.fromEntries(Object.entries(filePaths).map(([file, path]) => [path, files[file]])); - await request('init', {files: projectFiles}, 120000); + await request('init', {files: projectFiles}, pythonLoadTimeout); ready = true; } diff --git a/site/assets/python-worker.js b/site/assets/python-worker.js index 8118e3c..9985c40 100644 --- a/site/assets/python-worker.js +++ b/site/assets/python-worker.js @@ -1,9 +1,11 @@ import {loadPyodide} from './python-runtime/pyodide.mjs'; let python; async function initialize(files) { - self.postMessage({type:'status',text:'Loading the local Python runtime and scientific packages…'}); + self.postMessage({type:'status',text:'Downloading Python. The first run can take a few minutes.'}); python = await loadPyodide({indexURL:new URL('./python-runtime/',import.meta.url).href}); + self.postMessage({type:'status',text:'Loading pandas, NumPy, and Matplotlib…'}); await python.loadPackage(['numpy','pandas','matplotlib']); + self.postMessage({type:'status',text:'Preparing the workshop data…'}); const project = await fetch(new URL('./browser-project.json',import.meta.url)); if(!project.ok) throw new Error('Browser project files are missing. Rebuild the site.'); const bundled = (await project.json()).files;