marimo icon indicating copy to clipboard operation
marimo copied to clipboard

Feature request: context manager on "rest of run"

Open tjltjl opened this issue 1 year ago • 0 comments

Description

I want to start a background thread or open a persistent connection to a server. Usually, in python, the way to do these things cleanly is to use a context manager.

Suggested solution

In Marimo, what I'd like to do is basically say "run the rest of the computation within this context manager" so that if any of the descendants of a cell are run, the context is not broken but if the cell or its parents are edited, the context manager first exits and then restarts. Something like

do things
with my_background_thread():
    mo.descend()

where mo.descend only returns if this cell or its parents are edited.

Alternative

Some other way to set contexts that are torn down at the right time

Additional context

No response

tjltjl avatar Feb 02 '24 20:02 tjltjl