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
fix: put Inspector in typecheck (#4915)
Myles Scolnick272cce3c026a
diff --git a/marimo/_sql/engines/sqlalchemy.py b/marimo/_sql/engines/sqlalchemy.pyindex 864764311b..80b7f5206d 100644--- a/marimo/_sql/engines/sqlalchemy.py+++ b/marimo/_sql/engines/sqlalchemy.py@@ -24,7 +24,7 @@ from marimo._types.ids import VariableNameLOGGER = _loggers.marimo_logger()if TYPE_CHECKING:- from sqlalchemy import Engine+ from sqlalchemy import Engine, Inspectorfrom sqlalchemy.engine.cursor import CursorResultfrom sqlalchemy.sql.type_api import TypeEngine@@ -36,13 +36,14 @@ class SQLAlchemyEngine(SQLEngine):def __init__(self, connection: Engine, engine_name: Optional[VariableName] = None) -> None:- from sqlalchemy import Inspector, inspect-self._engine = connectionself._engine_name = engine_nameself.inspector: Optional[Inspector] = Nonetry:+ # May not exist in older versions of SQLAlchemy+ from sqlalchemy import inspect+self.inspector = inspect(self._engine)except Exception:LOGGER.warning("Failed to create inspector", exc_info=True)diff --git a/marimo/_utils/health.py b/marimo/_utils/health.pyindex 9b6b3da718..af7cdeb6f0 100644--- a/marimo/_utils/health.py+++ b/marimo/_utils/health.py@@ -10,6 +10,8 @@ from marimo import _loggersLOGGER = _loggers.marimo_logger()+TIMEOUT = 10 # seconds+def get_node_version() -> Optional[str]:try:@@ -19,7 +21,7 @@ def get_node_version() -> Optional[str]:stderr=subprocess.PIPE,text=True,)- stdout, stderr = process.communicate()+ stdout, stderr = communicate_with_timeout(process)if stderr:return Noneif stdout and (stripped := stdout.strip()):@@ -107,7 +109,7 @@ def get_chrome_version() -> Optional[str]:stderr=subprocess.PIPE,text=True,)- stdout, stderr = process.communicate()+ stdout, stderr = communicate_with_timeout(process)if stderr:return Noneparts = stdout.strip().split()@@ -125,7 +127,7 @@ def get_chrome_version() -> Optional[str]:stderr=subprocess.PIPE,text=True,)- stdout, stderr = process.communicate()+ stdout, stderr = communicate_with_timeout(process)if stderr:return Noneparts = stdout.strip().split()@@ -140,7 +142,7 @@ def get_chrome_version() -> Optional[str]:stderr=subprocess.PIPE,text=True,)- stdout, stderr = process.communicate()+ stdout, stderr = communicate_with_timeout(process)if stderr:return Noneparts = stdout.strip().split()@@ -166,3 +168,13 @@ def get_chrome_version() -> Optional[str]:def get_python_version() -> str:return sys.version.split()[0]+++def communicate_with_timeout(+ process: subprocess.Popen[str], timeout: float = TIMEOUT+) -> tuple[str, str]:+ try:+ return process.communicate(timeout=timeout)+ except subprocess.TimeoutExpired:+ process.kill()+ return "", "Error: Process timed out"diff --git a/tests/_utils/test_background_task.py b/tests/_utils/test_background_task.pyindex 6b362489ac..42aa0dec55 100644--- a/tests/_utils/test_background_task.py+++ b/tests/_utils/test_background_task.py@@ -83,20 +83,15 @@ async def test_stop_timeout():assert task.task.done()- reason="""- Works locally, but fails in CI.- RuntimeError: There is no current event loop in thread 'MainThread'-"""-)-def test_stop_sync():+async def test_stop_sync():task = SimpleTask()async def run():task.start()- asyncio.run(run())- task.stop_sync(timeout=0.1)+ await run()+ task.stop_sync(timeout=0.5)assert not task.runningassert task.task is not None- assert task.task.done()+ await asyncio.sleep(0) # Wait a tick+ assert task.task.done(), "Task should be done"