Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SafeCloseable context manager wrapper #5251

Merged
merged 9 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion py/server/deephaven/jcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ def _j_array_to_series(dtype: DType, j_array: jpy.JType, conv_null: bool) -> pd.


class SafeCloseable(JObjectWrapper):
arman-ddl marked this conversation as resolved.
Show resolved Hide resolved
"""A context manager wrapper of Java SafeCloseable to emulate Java try-with-resources."""
"""A context manager wrapper to allow Java SafeCloseable to be used in with statements. Assumes Java
SafeCloseable has not been closed yet."""
arman-ddl marked this conversation as resolved.
Show resolved Hide resolved

j_object_type = jpy.get_type("io.deephaven.util.SafeCloseable")

Expand Down
2 changes: 1 addition & 1 deletion py/server/tests/test_jcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def int_to_str(v: int) -> str:
def test_safe_closeable(self):
safe_closeable = SafeCloseable(_JSharedContext.makeSharedContext())
chipkent marked this conversation as resolved.
Show resolved Hide resolved
with safe_closeable:
pass
self.assertEqual(safe_closeable.closed, False)
self.assertEqual(safe_closeable.closed, True)


Expand Down
Loading