From 4a4c262973facc3e2d7d5ee82fa76c2cc135e8cd Mon Sep 17 00:00:00 2001 From: Alice Chen Date: Tue, 3 Mar 2026 16:00:30 -0800 Subject: [PATCH] fix: ensure batch processor flushes on interpreter shutdown Adds a more robust atexit handler that waits for the flush thread to complete. This fixes the race condition where the daemon thread is killed before the final flush. Closes #52 --- src/acme_sdk/utils/batching.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/acme_sdk/utils/batching.py diff --git a/src/acme_sdk/utils/batching.py b/src/acme_sdk/utils/batching.py new file mode 100644 index 0000000..2e95515 --- /dev/null +++ b/src/acme_sdk/utils/batching.py @@ -0,0 +1,10 @@ + + +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)