marimo icon indicating copy to clipboard operation
marimo copied to clipboard

Order of execution not coherent

Open jupiterMJM opened this issue 8 months ago • 3 comments

Describe the bug

Hey! First of all, Marimo is such a great alternative to Jupyter Notebook! So much more useful! But, I think I've ran into an issue, here is an example of program (see section "Code to reproduce")

In this program, we define a class that do some stuff which take some time. I gather some instances of this class into a list and I use this list in 2 cells:

  • the first one launch the function "do_some_stuff" that take some time and just "read" the variable a_list_of_class
  • the second one just print the time at which it is launched.

Here are the results I get: first cell: START : 1744043107.4414253 END : 1744043108.4445536

second cell: START : 1744043107.4247591

Therefore, we clearly see that the second cell is launched before the first one.... I ve put this issue as a bug as it does not seem normal but I may do something wrong! Thx a lot for your help!

Environment

{ "marimo": "0.12.4", "OS": "Windows", "OS Version": "10", "Processor": "Intel64 Family 6 Model 60 Stepping 3, GenuineIntel", "Python Version": "3.13.2", "Binaries": { "Browser": "--", "Node": "v22.14.0" }, "Dependencies": { "click": "8.1.8", "docutils": "0.21.2", "itsdangerous": "2.2.0", "jedi": "0.19.2", "markdown": "3.7", "narwhals": "1.34.0", "packaging": "24.2", "psutil": "7.0.0", "pygments": "2.19.1", "pymdown-extensions": "10.14.3", "pyyaml": "6.0.2", "ruff": "0.11.4", "starlette": "0.46.1", "tomlkit": "0.13.2", "typing-extensions": "4.13.1", "uvicorn": "0.34.0", "websockets": "15.0.1" }, "Optional Dependencies": { "altair": "5.5.0", "duckdb": "1.2.1", "pandas": "2.2.3", "polars": "1.26.0", "pyarrow": "19.0.1" }, "Experimental Flags": {} }

Code to reproduce

import marimo

__generated_with = "0.12.4"
app = marimo.App(width="medium")


@app.cell
def _():
    import time as t
    return (t,)


@app.cell
def _(t):
    class Test:
        def __init__(self):
            pass

        def do_some_stuff(self):
            # we do some stuff that take some time
            t.sleep(.1)
    return (Test,)


@app.cell
def _(Test):
    a_list_of_class = [Test() for _ in range(10)]
    return (a_list_of_class,)


@app.cell
def _(a_list_of_class, t):
    print(f"START : {t.time()}")
    for classe in a_list_of_class:
        classe.do_some_stuff()
    print(f"END : {t.time()}")
    return (classe,)


@app.cell
def _(a_list_of_class, t):
    a_list_of_class
    print(f"START : {t.time()}")
    return


@app.cell
def _():
    return


if __name__ == "__main__":
    app.run()

jupiterMJM avatar Apr 07 '25 16:04 jupiterMJM

I tried running your code but not could produce what you see (it seems to run in the correct order for me.

But also, the 3rd and 4th cell are not dependent on each other, so we don't guarantee the order in which they run. This may change in future when cells can be run in parallel.

mscolnick avatar Apr 07 '25 20:04 mscolnick

Hello, I ve re-run the program I gave and I ve seen that the order of execution changes over time (randomly, or at least i did not see any pattern). So, is there a way to force a launch in a specific order? Thanks

jupiterMJM avatar Apr 08 '25 08:04 jupiterMJM

@jupiterMJM you can force add a dependency between the two cells by declaring a variable in one and reference it in another.

mscolnick avatar Apr 08 '25 14:04 mscolnick

So if this is not a bug, should this issue be closed? I do not have permission to do so.

philipdeboer avatar Nov 09 '25 01:11 philipdeboer