diff --git a/py/server/deephaven/experimental/__init__.py b/py/server/deephaven/experimental/__init__.py index 7c9b59c9cb6..1a8de8a6347 100644 --- a/py/server/deephaven/experimental/__init__.py +++ b/py/server/deephaven/experimental/__init__.py @@ -7,6 +7,7 @@ import jpy from deephaven import DHError from deephaven.table import Table +from deephaven.update_graph import auto_locking_ctx _JWindowCheck = jpy.get_type("io.deephaven.engine.util.WindowCheck") @@ -31,6 +32,7 @@ def time_window(table: Table, ts_col: str, window: int, bool_col: str) -> Table: DHError """ try: - return Table(j_table=_JWindowCheck.addTimeWindow(table.j_table, ts_col, window, bool_col)) + with auto_locking_ctx(table): + return Table(j_table=_JWindowCheck.addTimeWindow(table.j_table, ts_col, window, bool_col)) except Exception as e: raise DHError(e, "failed to create a time window table.") from e diff --git a/py/server/tests/test_experiments.py b/py/server/tests/test_experiments.py index fd04cce0c65..db492428104 100644 --- a/py/server/tests/test_experiments.py +++ b/py/server/tests/test_experiments.py @@ -66,15 +66,24 @@ def test_left_outer_join(self): self.assertRegex(str(cm.exception), r"Conflicting column names") def test_time_window(self): - with exclusive_lock(self.test_update_graph): + with self.subTest("user-explicit lock"): + with exclusive_lock(self.test_update_graph): + source_table = time_table("PT00:00:00.01").update(["TS=now()"]) + t = time_window(source_table, ts_col="TS", window=10 ** 8, bool_col="InWindow") + + self.assertEqual("InWindow", t.columns[-1].name) + self.wait_ticking_table_update(t, row_count=20, timeout=60) + self.assertIn("true", t.to_string(1000)) + self.assertIn("false", t.to_string(1000)) + + with self.subTest("auto-lock"): source_table = time_table("PT00:00:00.01").update(["TS=now()"]) t = time_window(source_table, ts_col="TS", window=10 ** 8, bool_col="InWindow") - self.assertEqual("InWindow", t.columns[-1].name) - self.wait_ticking_table_update(t, row_count=20, timeout=60) - self.assertIn("true", t.to_string(1000)) - self.assertIn("false", t.to_string(1000)) - + self.assertEqual("InWindow", t.columns[-1].name) + self.wait_ticking_table_update(t, row_count=20, timeout=60) + self.assertIn("true", t.to_string(1000)) + self.assertIn("false", t.to_string(1000)) if __name__ == '__main__': unittest.main()