Release TensorStore context and event loop on colocated Python workers.
(self)
| 106 | ).result() |
| 107 | |
| 108 | def teardown(self): |
| 109 | """Release TensorStore context and event loop on colocated Python workers.""" |
| 110 | if hasattr(self, "event_loop") and self.event_loop is not None: |
| 111 | # Shut down the default executor before stopping the loop (1 min timeout). |
| 112 | asyncio.run_coroutine_threadsafe( |
| 113 | self.event_loop.shutdown_default_executor( |
| 114 | timeout=60 |
| 115 | ), # pytype: disable=wrong-keyword-args |
| 116 | self.event_loop, |
| 117 | ).result() |
| 118 | self.event_loop.call_soon_threadsafe(self.event_loop.stop) |
| 119 | self.loop_thread.join() |
| 120 | self.event_loop.close() |
| 121 | self.event_loop = None |
| 122 | self.ts_context = None |
| 123 | logging.info("ColocatedStateManager destroyed on sidecar.") |
| 124 | |
| 125 | def __del__(self): |
| 126 | self.teardown() |