Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit a91fea2

Browse files
committed
Don't wait to flush async worker queue on exit (#384)
1 parent 7d863e1 commit a91fea2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

opencensus/common/transports/async_.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import atexit
1616
import logging
1717
import threading
18-
import time
1918

2019
from six.moves import queue
2120
from six.moves import range
@@ -54,6 +53,7 @@ def __init__(self, exporter, grace_period=_DEFAULT_GRACE_PERIOD,
5453
self._max_batch_size = max_batch_size
5554
self._queue = queue.Queue(0)
5655
self._lock = threading.Lock()
56+
self._event = threading.Event()
5757
self._thread = None
5858

5959
@property
@@ -114,8 +114,10 @@ def _thread_main(self):
114114
for _ in range(len(items)):
115115
self._queue.task_done()
116116

117-
# Wait for a while before next export
118-
time.sleep(_WAIT_PERIOD)
117+
# self._event is set at exit, at which point we start draining the
118+
# queue immediately. If self._event is unset, block for
119+
# _WAIT_PERIOD between each batch of exports.
120+
self._event.wait(_WAIT_PERIOD)
119121

120122
if quit_:
121123
break
@@ -165,6 +167,8 @@ def _export_pending_data(self):
165167
"""Callback that attempts to send pending data before termination."""
166168
if not self.is_alive:
167169
return
170+
# Stop blocking between export batches
171+
self._event.set()
168172
self.stop()
169173

170174
def enqueue(self, data):

0 commit comments

Comments
 (0)