Skip to content

Commit a942810

Browse files
authored
Clarify worker thread implementation. (#8228)
1 parent b662d75 commit a942810

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

google/cloud/logging/handlers/transports/background_thread.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import threading
2626
import time
2727

28-
from six.moves import range
2928
from six.moves import queue
3029

3130
from google.cloud.logging.handlers.transports.base import Transport
@@ -56,8 +55,8 @@ def _get_many(queue_, max_items=None, max_latency=0):
5655
item from a queue. This number includes the time required to retrieve
5756
the first item.
5857
59-
:rtype: Sequence
60-
:returns: A sequence of items retrieved from the queue.
58+
:rtype: list
59+
:returns: items retrieved from the queue.
6160
"""
6261
start = time.time()
6362
# Always return at least one item.
@@ -132,8 +131,8 @@ def _thread_main(self):
132131
"""
133132
_LOGGER.debug("Background thread started.")
134133

135-
quit_ = False
136-
while True:
134+
done = False
135+
while not done:
137136
batch = self._cloud_logger.batch()
138137
items = _get_many(
139138
self._queue,
@@ -143,20 +142,15 @@ def _thread_main(self):
143142

144143
for item in items:
145144
if item is _WORKER_TERMINATOR:
146-
quit_ = True
147-
# Continue processing items, don't break, try to process
148-
# all items we got back before quitting.
145+
done = True # Continue processing items.
149146
else:
150147
batch.log_struct(**item)
151148

152149
self._safely_commit_batch(batch)
153150

154-
for _ in range(len(items)):
151+
for _ in items:
155152
self._queue.task_done()
156153

157-
if quit_:
158-
break
159-
160154
_LOGGER.debug("Background thread exited gracefully.")
161155

162156
def start(self):

0 commit comments

Comments
 (0)