@@ -255,10 +255,11 @@ def __init__(self, name: str, min_level: int = LOG_LEVEL_INFO):
255255 _ensure_async_worker ()
256256
257257 def close (self ) -> None :
258- """Flush pending messages and release resources for this logger instance ."""
258+ """Best-effort flush of pending messages for this logger by waiting briefly ."""
259259 # Draining items belonging to this logger from the queue would require
260260 # restructuring the shared queue, so we do a best-effort flush by
261- # waiting briefly for the background worker to catch up.
261+ # waiting briefly for the background worker to catch up. This does not
262+ # guarantee that all enqueued messages have been processed.
262263 time .sleep (_ASYNC_CLOSE_WAIT_SECS )
263264
264265 def _log_async (self , level : int , message : str , fields : Optional [Dict [str , Any ]] = None ) -> None :
@@ -309,10 +310,11 @@ def exception(self, message: str, **fields) -> None:
309310 self ._log_async (40 , message , fields )
310311
311312 def flush (self ) -> None :
312- """Flush pending messages (best effort)."""
313- # For async logger, we can't force immediate flush
314- # but we can yield to allow background processing
315- time .sleep (0.001 )
313+ """Best-effort, timing-based flush by yielding to the background worker."""
314+ # For async logger, we can't force immediate flush, but we can yield
315+ # briefly to allow background processing. This does not guarantee that
316+ # all pending messages have been processed.
317+ time .sleep (_ASYNC_CLOSE_WAIT_SECS )
316318
317319
318320# Lock-free logger cache using thread-local storage
0 commit comments