Skip to content

Commit 9c79e01

Browse files
datumboxfchollet
authored andcommitted
Fixing finite generator race condition (keras-team#8162)
* Fixing race condition Check again for empty queue after detecting that all threads have finished. * Updating the test to check for all set items
1 parent e93b854 commit 9c79e01

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

keras/utils/data_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ def get(self):
654654
yield inputs
655655
else:
656656
all_finished = all([not thread.is_alive() for thread in self._threads])
657-
if all_finished:
657+
if all_finished and self.queue.empty():
658658
raise StopIteration()
659659
else:
660660
time.sleep(self.wait_time)

tests/keras/utils/data_utils_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def test_finite_generator_enqueuer_threads():
264264
acc = []
265265
for output in gen_output:
266266
acc.append(int(output[0, 0, 0, 0]))
267-
assert len(set(acc) - set(range(100))) == 0, "Output is not the same"
267+
assert set(acc) == set(range(100)), "Output is not the same"
268268
enqueuer.stop()
269269

270270

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy