diff --git a/src/acme_sdk/utils/batching.py b/src/acme_sdk/utils/batching.py index 0895a46..b9aa7f0 100644 --- a/src/acme_sdk/utils/batching.py +++ b/src/acme_sdk/utils/batching.py @@ -99,3 +99,13 @@ def shutdown(self, timeout: float | None = None) -> None: if timeout is None: timeout = self._flush_interval * 3 self._thread.join(timeout=timeout) + + +def _ensure_flush_on_shutdown(processor: BatchProcessor) -> None: + """Ensure final flush happens before interpreter exit. + + This is registered as an atexit handler and ensures that the + background flush thread completes before the interpreter exits. + """ + if not processor._shutdown: + processor.shutdown(timeout=processor._flush_interval * 3)