A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
Use explicit mulitprocessing `getcontext("spawn")` (#8705)
Myles Scolnick18d212f2a00d
diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.ymlindex 3b35e5c6fb..3f1de7f30c 100644--- a/.github/workflows/playwright.yml+++ b/.github/workflows/playwright.yml@@ -33,7 +33,7 @@ jobs:test:needs: changesif: ${{ needs.changes.outputs.playwright == 'true' }}- timeout-minutes: 13 # 2024-01-18 avg: 5.0m max: 7.0m+ timeout-minutes: 18 # 2024-01-18 avg: 5.0m max: 7.0mruns-on: ubuntu-latestdefaults:run:diff --git a/frontend/e2e-tests/py/components.py b/frontend/e2e-tests/py/components.pyindex 25ec999abf..c4a35540cf 100644--- a/frontend/e2e-tests/py/components.py+++ b/frontend/e2e-tests/py/components.py@@ -207,7 +207,7 @@ def __(mo):if values is not None and isinstance(values, list):return all(isinstance(v, str) for v in values)- if element is not None:+ if element is not None and hasattr(element, "value"):v = (element.valueif not isinstance(element, mo.ui.file)diff --git a/marimo/_session/managers/kernel.py b/marimo/_session/managers/kernel.pyindex 8805ff96e5..c122515d6b 100644--- a/marimo/_session/managers/kernel.py+++ b/marimo/_session/managers/kernel.py@@ -8,7 +8,7 @@ import signalimport sysimport threadingimport time-from multiprocessing import Process, connection+from multiprocessing import connection, get_contextfrom typing import TYPE_CHECKING, Any, Optional, Unionfrom uuid import uuid4@@ -71,7 +71,7 @@ class KernelManagerImpl(KernelManager):if is_edit_mode:# Need to use a socket for windows compatibilitylistener = connection.Listener(family="AF_INET")- self.kernel_task = Process(+ self.kernel_task = get_context("spawn").Process(target=runtime.launch_kernel,args=(self.queue_manager.control_queue,diff --git a/tests/_cli/snapshots/export/ipynb/ipynb_with_media_outputs.txt b/tests/_cli/snapshots/export/ipynb/ipynb_with_media_outputs.txtindex 70932fa76a..41b19884a0 100644--- a/tests/_cli/snapshots/export/ipynb/ipynb_with_media_outputs.txt+++ b/tests/_cli/snapshots/export/ipynb/ipynb_with_media_outputs.txt@@ -340,7 +340,7 @@"data": {"text/html": ["<div> <script>window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n",- " <script charset=\"utf-8\" src=\"https://cdn.plot.ly/plotly-VERSION.min.js\" integrity=\"INTEGRITY_HASH\" crossorigin=\"anonymous\"></script> <div id=\"PLOTLY_DIV_ID\" class=\"plotly-graph-div\" style=\"height:100%; width:100%;\"></div> <script> window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById(\"PLOTLY_DIV_ID\")) { Plotly.newPlot(\"PLOTLY_DIV_ID\", [{\"mode\":\"lines+markers\",\"x\":{\"dtype\":\"i1\",\"bdata\":\"PLOTLY_BINARY_DATA\"},\"y\":{\"dtype\":\"f8\",\"bdata\":\"FB+RNhI93D\\u002fi42YA+izVvw==\"},\"type\":\"scatter\"}], {\"template\":{\"data\":{\"histogram2dcontour\":[{\"type\":\"histogram2dcontour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"choropleth\":[{\"type\":\"choropleth\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"histogram2d\":[{\"type\":\"histogram2d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmap\":[{\"type\":\"heatmap\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"type\":\"contourcarpet\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"contour\":[{\"type\":\"contour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"surface\":[{\"type\":\"surface\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"mesh3d\":[{\"type\":\"mesh3d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"scatter\":[{\"marker\":{\"line\":{\"color\":\"#283442\"}},\"type\":\"scatter\"}],\"parcoords\":[{\"type\":\"parcoords\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolargl\":[{\"type\":\"scatterpolargl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"bar\":[{\"error_x\":{\"color\":\"#f2f5fa\"},\"error_y\":{\"color\":\"#f2f5fa\"},\"marker\":{\"line\":{\"color\":\"rgb(17,17,17)\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"scattergeo\":[{\"type\":\"scattergeo\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolar\":[{\"type\":\"scatterpolar\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"scattergl\":[{\"marker\":{\"line\":{\"color\":\"#283442\"}},\"type\":\"scattergl\"}],\"scatter3d\":[{\"type\":\"scatter3d\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattermap\":[{\"type\":\"scattermap\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattermapbox\":[{\"type\":\"scattermapbox\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterternary\":[{\"type\":\"scatterternary\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattercarpet\":[{\"type\":\"scattercarpet\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#A2B1C6\",\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"minorgridcolor\":\"#506784\",\"startlinecolor\":\"#A2B1C6\"},\"baxis\":{\"endlinecolor\":\"#A2B1C6\",\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"minorgridcolor\":\"#506784\",\"startlinecolor\":\"#A2B1C6\"},\"type\":\"carpet\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#506784\"},\"line\":{\"color\":\"rgb(17,17,17)\"}},\"header\":{\"fill\":{\"color\":\"#2a3f5f\"},\"line\":{\"color\":\"rgb(17,17,17)\"}},\"type\":\"table\"}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"rgb(17,17,17)\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}]},\"layout\":{\"autotypenumbers\":\"strict\",\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#f2f5fa\"},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"paper_bgcolor\":\"rgb(17,17,17)\",\"plot_bgcolor\":\"rgb(17,17,17)\",\"polar\":{\"bgcolor\":\"rgb(17,17,17)\",\"angularaxis\":{\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"ticks\":\"\"},\"radialaxis\":{\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"ticks\":\"\"}},\"ternary\":{\"bgcolor\":\"rgb(17,17,17)\",\"aaxis\":{\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"ticks\":\"\"},\"caxis\":{\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"ticks\":\"\"}},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]]},\"xaxis\":{\"gridcolor\":\"#283442\",\"linecolor\":\"#506784\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"#283442\",\"automargin\":true,\"zerolinewidth\":2},\"yaxis\":{\"gridcolor\":\"#283442\",\"linecolor\":\"#506784\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"#283442\",\"automargin\":true,\"zerolinewidth\":2},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"rgb(17,17,17)\",\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"#C8D4E3\",\"gridwidth\":2},\"yaxis\":{\"backgroundcolor\":\"rgb(17,17,17)\",\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"#C8D4E3\",\"gridwidth\":2},\"zaxis\":{\"backgroundcolor\":\"rgb(17,17,17)\",\"gridcolor\":\"#506784\",\"linecolor\":\"#506784\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"#C8D4E3\",\"gridwidth\":2}},\"shapedefaults\":{\"line\":{\"color\":\"#f2f5fa\"}},\"annotationdefaults\":{\"arrowcolor\":\"#f2f5fa\",\"arrowhead\":0,\"arrowwidth\":1},\"geo\":{\"bgcolor\":\"rgb(17,17,17)\",\"landcolor\":\"rgb(17,17,17)\",\"subunitcolor\":\"#506784\",\"showland\":true,\"showlakes\":true,\"lakecolor\":\"rgb(17,17,17)\"},\"title\":{\"x\":0.05},\"updatemenudefaults\":{\"bgcolor\":\"#506784\",\"borderwidth\":0},\"sliderdefaults\":{\"bgcolor\":\"#C8D4E3\",\"borderwidth\":1,\"bordercolor\":\"rgb(17,17,17)\",\"tickwidth\":0},\"mapbox\":{\"style\":\"dark\"}}},\"dragmode\":\"zoom\"}, {\"responsive\": true} ) }; </script> </div>"+ " <script charset=\"utf-8\" src=\"https://cdn.plot.ly/plotly-VERSION.min.js\" integrity=\"INTEGRITY_HASH\" crossorigin=\"anonymous\"></script> <div id=\"PLOTLY_DIV_ID\" class=\"plotly-graph-div\" style=\"height:100%; width:100%;\"></div> <script> window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById(\"PLOTLY_DIV_ID\")) { Plotly.newPlot(\"PLOTLY_DIV_ID\", [{\"mode\":\"lines+markers\",\"x\":{\"dtype\":\"i1\",\"bdata\":\"PLOTLY_BINARY_DATA\"},\"y\":{\"dtype\":\"f8\",\"bdata\":\"FB+RNhI93D\\u002fi42YA+izVvw==\"},\"type\":\"scatter\"}], {\"template\":\"PLOTLY_TEMPLATE\",\"dragmode\":\"zoom\"}, {\"responsive\": true} ) }; </script> </div>"]},"metadata": {},diff --git a/tests/_cli/snapshots/export/md/async.txt b/tests/_cli/snapshots/export/md/async.txtindex a29ff20a16..a61ae45e51 100644--- a/tests/_cli/snapshots/export/md/async.txt+++ b/tests/_cli/snapshots/export/md/async.txt@@ -1,5 +1,5 @@----title: Notebook+title: Notebook Asyncmarimo-version: 0.0.0---diff --git a/tests/_cli/snapshots/export/md/broken.txt b/tests/_cli/snapshots/export/md/broken.txtindex 8aea641ac2..5bb0475126 100644--- a/tests/_cli/snapshots/export/md/broken.txt+++ b/tests/_cli/snapshots/export/md/broken.txt@@ -1,5 +1,5 @@----title: Notebook+title: Notebook Unparsablemarimo-version: 0.0.0---diff --git a/tests/_cli/snapshots/export/md/export_markdown_with_errors.txt b/tests/_cli/snapshots/export/md/export_markdown_with_errors.txtindex 8ffd58552a..b70db48534 100644--- a/tests/_cli/snapshots/export/md/export_markdown_with_errors.txt+++ b/tests/_cli/snapshots/export/md/export_markdown_with_errors.txt@@ -1,5 +1,5 @@----title: Notebook+title: Notebook With Errorsmarimo-version: 0.0.0---diff --git a/tests/mocks.py b/tests/mocks.pyindex 5d4e6dda21..ea9461e18f 100644--- a/tests/mocks.py+++ b/tests/mocks.py@@ -163,6 +163,41 @@ def simplify_images(output: str) -> str:return output+def _replace_braced_value(text: str, key: str, placeholder: str) -> str:+ """Replace a JSON object value (the {...} after *key*) with a placeholder.++ Uses brace-counting so it works with arbitrarily nested objects.+ The quote style is inferred from *key* so the placeholder matches the+ surrounding context (e.g. escaped ``\\"`` vs plain ``"``).+ """+ q = '\\"' if '\\"' in key else '"'+ idx = 0+ while True:+ pos = text.find(key, idx)+ if pos == -1:+ break+ brace_start = text.find("{", pos + len(key))+ if brace_start == -1:+ break+ depth = 0+ i = brace_start+ while i < len(text):+ if text[i] == "{":+ depth += 1+ elif text[i] == "}":+ depth -= 1+ if depth == 0:+ text = (+ text[: pos + len(key)]+ + f"{q}{placeholder}{q}"+ + text[i + 1 :]+ )+ break+ i += 1+ idx = pos + 1+ return text++def simplify_plotly(output: str) -> str:"""Simplify plotly output for consistent snapshots."""# Replace any <marimo-plotly ...>...</marimo-plotly> (attributes or not, any whitespace, multiline)@@ -251,6 +286,11 @@ def simplify_plotly(output: str) -> str:output,)+ # Replace the Plotly template (theme) JSON object which varies by version.+ # Uses brace-counting since the template is deeply nested.+ for marker in (r"\"template\":", '"template":'):+ output = _replace_braced_value(output, marker, "PLOTLY_TEMPLATE")+return output