Skip to content

fix(export): allow WebPDF export on Windows#10131

Merged
mscolnick merged 4 commits into
marimo-team:mainfrom
peter-gy:ptr/fix-pdf-export-incompat
Jul 10, 2026
Merged

fix(export): allow WebPDF export on Windows#10131
mscolnick merged 4 commits into
marimo-team:mainfrom
peter-gy:ptr/fix-pdf-export-incompat

Conversation

@peter-gy

@peter-gy peter-gy commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

WebPDF export launches Chromium as a child process. On Windows, marimo uses an async event loop that can monitor notebook connections but cannot launch child processes, so nbconvert fails before Chromium renders the notebook.

This PR renders WebPDF in a separate Windows process. The renderer uses the Proactor event loop to start Chromium, while the marimo server keeps the event loop it needs for notebook connections.

Fixes #9713

@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jul 10, 2026 7:49am

Request Review

@peter-gy peter-gy added the bug Something isn't working label Jul 10, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Architecture diagram
sequenceDiagram
    participant User
    participant CLI as CLI (commands.py)
    participant FileWatcher as File Watcher
    participant ExportManager as Exporter (exporter.py)
    participant EventLoop as Event Loop Policy
    participant nbconvert as nbconvert WebPDFExporter
    participant Playwright as Playwright / Subprocess

    Note over User,ExportManager: Watch-mode WebPDF export flow (Windows fix)

    User->>CLI: marimo export --watch --webpdf
    CLI->>FileWatcher: start watching notebook file

    Note over FileWatcher,CLI: File change detected

    FileWatcher-->>CLI: on_file_changed(path)
    CLI->>CLI: acquire export_lock (async)
    CLI->>ExportManager: export_callback(MarimoPath)

    Note over ExportManager: export_as_pdf(webpdf=True)

    ExportManager->>ExportManager: check sys.platform == "win32" and webpdf

    alt On Windows (Win32)
        ExportManager->>EventLoop: get_event_loop_policy()
        EventLoop-->>ExportManager: previous_policy (WindowsSelector...)
        ExportManager->>EventLoop: set_event_loop_policy(None)
        Note over ExportManager: Reset to default ProactorEventLoop

        ExportManager->>nbconvert: from_notebook_node(notebook)
        nbconvert->>Playwright: spawn chromium subprocess
        Playwright-->>nbconvert: PDF data
        nbconvert-->>ExportManager: pdf_data, resources

        ExportManager->>EventLoop: set_event_loop_policy(previous_policy)
        Note over ExportManager: Restore original selector policy
    else Non-Windows (or not webpdf)
        ExportManager->>nbconvert: from_notebook_node(notebook)
        nbconvert-->>ExportManager: pdf_data, resources
    end

    ExportManager-->>CLI: bytes PDF data
    CLI->>CLI: release export_lock
    CLI-->>User: PDF written to output file
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread marimo/_server/export/exporter.py Outdated
@peter-gy
peter-gy requested a review from Copilot July 10, 2026 06:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@peter-gy
peter-gy marked this pull request as ready for review July 10, 2026 08:24
@peter-gy
peter-gy requested review from Light2Dark and mscolnick July 10, 2026 08:25
@mscolnick
mscolnick merged commit 0af89ee into marimo-team:main Jul 10, 2026
57 of 58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pdf export using webpdf fails

3 participants