Skip to content

Commit

Permalink
SectionExecutor: Catch empty queue
Browse files Browse the repository at this point in the history
  • Loading branch information
sils committed May 16, 2015
1 parent 1a59a0d commit 98f3af4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
27 changes: 15 additions & 12 deletions coalib/processes/SectionExecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,21 @@ def _process_queues(self,
global_result_buffer = []

# One process is the logger thread
while local_processes > 1:
control_elem, index = control_queue.get(timeout=0.1)

if control_elem == CONTROL_ELEMENT.LOCAL_FINISHED:
local_processes -= 1
elif control_elem == CONTROL_ELEMENT.LOCAL:
assert local_processes != 0
self.interactor.print_results(local_result_dict[index],
file_dict)
retval = retval or len(local_result_dict[index]) > 0
elif control_elem == CONTROL_ELEMENT.GLOBAL:
global_result_buffer.append(index)
while local_processes > 1 and running_processes > 1:
try:
control_elem, index = control_queue.get(timeout=0.1)

if control_elem == CONTROL_ELEMENT.LOCAL_FINISHED:
local_processes -= 1
elif control_elem == CONTROL_ELEMENT.LOCAL:
assert local_processes != 0
self.interactor.print_results(local_result_dict[index],
file_dict)
retval = retval or len(local_result_dict[index]) > 0
elif control_elem == CONTROL_ELEMENT.GLOBAL:
global_result_buffer.append(index)
except queue.Empty:
running_processes = self._get_running_processes(processes)

# Flush global result buffer
for elem in global_result_buffer:
Expand Down
9 changes: 9 additions & 0 deletions coalib/tests/processes/SectionExecutorTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ def test_process_queues(self):
self.assertEqual(mock_interactor.get(),
("The one and only global result.", None))

# No valid FINISH element in the queue
ctrlq.put((CONTROL_ELEMENT.GLOBAL_FINISHED, None))

uut.process_queues(ctrlq,
{1: "The first result.", 2: "The second result."},
{1: "The one and only global result."})
with self.assertRaises(queue.Empty):
mock_interactor.get()


if __name__ == '__main__':
unittest.main(verbosity=2)

1 comment on commit 98f3af4

@Makman2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Please sign in to comment.