Closed
Description
Describe the bug
Today, I am learning the source code of openai-agents-python. I use the latest commit 4cb011c. A tiny error has been found.
In the openai-agents-python/src/agents/tracing/processors.py
, the code developer repeatedly declares variable self._shutdown_event
in the line 177 and line 185.
Here is the code
class BatchTraceProcessor(TracingProcessor):
"""Some implementation notes:
1. Using Queue, which is thread-safe.
2. Using a background thread to export spans, to minimize any performance issues.
3. Spans are stored in memory until they are exported.
"""
def __init__(
self,
exporter: TracingExporter,
max_queue_size: int = 8192,
max_batch_size: int = 128,
schedule_delay: float = 5.0,
export_trigger_ratio: float = 0.7,
):
"""
Args:
exporter: The exporter to use.
max_queue_size: The maximum number of spans to store in the queue. After this, we will
start dropping spans.
max_batch_size: The maximum number of spans to export in a single batch.
schedule_delay: The delay between checks for new spans to export.
export_trigger_ratio: The ratio of the queue size at which we will trigger an export.
"""
self._exporter = exporter
self._queue: queue.Queue[Trace | Span[Any]] = queue.Queue(maxsize=max_queue_size)
self._max_queue_size = max_queue_size
self._max_batch_size = max_batch_size
self._schedule_delay = schedule_delay
self._shutdown_event = threading.Event()
# The queue size threshold at which we export immediately.
self._export_trigger_size = int(max_queue_size * export_trigger_ratio)
# Track when we next *must* perform a scheduled export
self._next_export_time = time.time() + self._schedule_delay
self._shutdown_event = threading.Event()
self._worker_thread = threading.Thread(target=self._run, daemon=True)
self._worker_thread.start()
Expected behavior
Maybe you should delete the declaration of line 185.