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):
877877 # ... some operations ...
878878 del dendrite # This will implicitly invoke the __del__ method and close the session.
879879 """
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+ )
881888
882889
883890# 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):
8383 assert setup_dendrite ._session is None
8484
8585
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+
8697@pytest .mark .asyncio
8798async def test_aclose (setup_dendrite , setup_axon ):
8899 axon = setup_axon
You can’t perform that action at this time.
0 commit comments