Skip to content

Commit

Permalink
fix: try to load worker from file, and fallback to inline (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
mscolnick authored Mar 15, 2024
1 parent 2f32a58 commit 2cd3ea3
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions frontend/src/core/pyodide/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,24 @@ export class PyodideBridge implements RunRequests, EditRequests {

constructor() {
if (isPyodide()) {
// Create a worker
const worker = new InlineWorker({
name: getMarimoVersion(),
});
// Create a worker, try by URL then inline
let worker: Worker;
const version = getMarimoVersion();
if (window.Worker) {
try {
worker = new Worker(new URL("worker/worker", import.meta.url), {
type: "module",
/* @vite-ignore */
name: version,
});
} catch {
Logger.debug("Failed to create worker by URL, trying inline.");
worker = new InlineWorker({ name: version });
}
} else {
Logger.debug("Worker not available, using inline worker.");
worker = new InlineWorker({ name: version });
}

// Create the RPC
this.rpc = getWorkerRPC(worker);
Expand Down

0 comments on commit 2cd3ea3

Please sign in to comment.