Skip to content

Import time signal handler install crashes from non-main threads such as marimo #136

Description

@ntnadkarni

Description

cwsandbox/_cleanup.py calls _install_handlers() at module load, which calls signal.signal(). That only works on the main thread, so simply importing cwsandbox from a worker thread crashes with ValueError: signal only works in main thread of the main interpreter.

import threading
threading.Thread(target=lambda: __import__("cwsandbox")).start()
# ValueError: signal only works in main thread of the main interpreter

marimo executes the with app.setup: block from a worker thread, so any marimo notebook that imports cwsandbox in setup fails before the first cell renders.

This is not a hard blocker. For now I have a workaround in my marimo notebook that catches the ValueError and restores the original just wanted to file this in case it impacts others

Steps to reproduce

import marimo
app = marimo.App()

with app.setup:
    from cwsandbox import Sandbox  

Expected behavior

Import should succeed.

Actual behavior

ValueError: signal only works in main thread of the main interpreter

cwsandbox version

0.24.0

Python version

3.13.9

Operating system

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions