Skip to content

Commit

Permalink
Fixing finite generator race condition (keras-team#8162)
Browse files Browse the repository at this point in the history
* Fixing race condition

Check again for empty queue after detecting that all threads have finished.

* Updating the test to check for all set items
  • Loading branch information
datumbox authored and fchollet committed Oct 19, 2017
1 parent e93b854 commit 9c79e01
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion keras/utils/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ def get(self):
yield inputs
else:
all_finished = all([not thread.is_alive() for thread in self._threads])
if all_finished:
if all_finished and self.queue.empty():
raise StopIteration()
else:
time.sleep(self.wait_time)
2 changes: 1 addition & 1 deletion tests/keras/utils/data_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def test_finite_generator_enqueuer_threads():
acc = []
for output in gen_output:
acc.append(int(output[0, 0, 0, 0]))
assert len(set(acc) - set(range(100))) == 0, "Output is not the same"
assert set(acc) == set(range(100)), "Output is not the same"
enqueuer.stop()


Expand Down

0 comments on commit 9c79e01

Please sign in to comment.