File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -877,7 +877,14 @@ def __del__(self):
877
877
# ... some operations ...
878
878
del dendrite # This will implicitly invoke the __del__ method and close the session.
879
879
"""
880
- self .close_session ()
880
+ try :
881
+ self .close_session ()
882
+ except RuntimeError :
883
+ if self ._session :
884
+ logging .debug (
885
+ "A Dendrite session was unable to be closed during garbage-collection of the Dendrite object. This "
886
+ "usually indicates that you were not using the async context manager."
887
+ )
881
888
882
889
883
890
# For back-compatibility with torch
Original file line number Diff line number Diff line change @@ -83,6 +83,17 @@ def test_close(setup_dendrite, setup_axon):
83
83
assert setup_dendrite ._session is None
84
84
85
85
86
+ def test_garbage_collection (setup_dendrite ):
87
+ del setup_dendrite # should not raise an error
88
+
89
+
90
+ @pytest .mark .asyncio
91
+ async def test_async_garbage_collection (setup_dendrite , setup_axon ):
92
+ async with setup_dendrite as dendrite :
93
+ assert (await dendrite .session ) is not None
94
+ del setup_dendrite # should not raise error
95
+
96
+
86
97
@pytest .mark .asyncio
87
98
async def test_aclose (setup_dendrite , setup_axon ):
88
99
axon = setup_axon
You can’t perform that action at this time.
0 commit comments