From ee90d95d972895159bbeb420ef823aba0416b9db Mon Sep 17 00:00:00 2001 From: James Baskerville Date: Fri, 7 Mar 2025 18:23:04 +0000 Subject: [PATCH] fix: Add sleep to OTEL exporters Infinite polling the export queue without a sleep was causing threads to take up a full core of CPU. Simple sleep fixes that. --- src/humanloop/otel/exporter/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/humanloop/otel/exporter/__init__.py b/src/humanloop/otel/exporter/__init__.py index b3220488..681deb76 100644 --- a/src/humanloop/otel/exporter/__init__.py +++ b/src/humanloop/otel/exporter/__init__.py @@ -1,5 +1,6 @@ import logging +import time import typing from queue import Empty as EmptyQueue from queue import Queue @@ -129,7 +130,8 @@ def _do_work(self): # Don't block or the thread will never be notified of the shutdown thread_args = self._upload_queue.get(block=False) # type: ignore except EmptyQueue: - # Wait for the another span to arrive + # Wait for another span to arrive + time.sleep(0.1) continue span_to_export, eval_context_callback = thread_args