Skip to content

Commit b85f4b7

Browse files
author
Matt Sokoloff
committed
recommended changes
1 parent 87b0f03 commit b85f4b7

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

labelbox/data/annotation_types/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def _add_url_to_data(label: Label):
191191
label.add_url_to_data(signer)
192192
return label
193193

194-
self._fns['_add_url_to_data'] = _add_url_to_data
194+
self._fns['add_url_to_data'] = _add_url_to_data
195195
return self
196196

197197
def add_to_dataset(self, dataset: "Entity.Dataset",

labelbox/data/generator.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import threading
33
from queue import Queue
44
from typing import Any, Iterable
5+
from concurrent.futures import ThreadPoolExecutor
56

67
logger = logging.getLogger(__name__)
78

@@ -44,14 +45,12 @@ def __init__(self,
4445
self.queue = Queue(prefetch_limit)
4546
self._data = ThreadSafeGen(self._data)
4647
self.completed_threads = 0
48+
self.done = False
4749
self.max_concurrency = max_concurrency
48-
self.threads = [
49-
threading.Thread(target=self.fill_queue)
50-
for _ in range(max_concurrency)
51-
]
52-
for thread in self.threads:
53-
thread.daemon = True
54-
thread.start()
50+
with ThreadPoolExecutor(max_workers=max_concurrency) as executor:
51+
self.futures = [
52+
executor.submit(self.fill_queue) for _ in range(max_concurrency)
53+
]
5554

5655
def _process(self, value) -> Any:
5756
raise NotImplementedError("Abstract method needs to be implemented")
@@ -73,12 +72,13 @@ def __iter__(self):
7372
return self
7473

7574
def __next__(self) -> Any:
75+
if self.done:
76+
raise StopIteration
7677
value = self.queue.get()
7778
while value is None:
7879
self.completed_threads += 1
7980
if self.completed_threads == self.max_concurrency:
80-
for thread in self.threads:
81-
thread.join()
81+
self.done = True
8282
raise StopIteration
8383
value = self.queue.get()
8484
return value

0 commit comments

Comments
 (0)