Commit fbb75c31 authored by Jan Losinski's avatar Jan Losinski Committed by Joaquim Rocha

fix a race condition in parallel recognizion

The worker had a state to signal that he has done. This state was set to
late so that no finish callback see that the worker is ready.

This commit simply drop the extra state and use the counter counting how
many callbacks where called. If the counter has the same value as the
page count it assumes that this is the last one - and updates, close the
dialog, ...
Signed-off-by: default avatarJan Losinski <losinski@wh2.tu-dresden.de>
parent b45eb02a
......@@ -653,7 +653,7 @@ class ImageReviewer_Controler:
page.data_boxes = data_boxes
with _pages_recognized_count_lock:
if dialog.worker.done and self._pages_recognized_count == (len(pages_to_process) - 1):
if self._pages_recognized_count == (len(pages_to_process) - 1):
dialog.cancel()
self.__updateImageReviewers()
self._pages_recognized_count +=1
......
......@@ -78,8 +78,6 @@ class AsyncWorker(Thread):
self.running_items = []
self.worker_threads = []
self.thread_sem = BoundedSemaphore(value=parallel)
self.done = False
self.queue_processing = True
self.process_pool = None
if parallel > 1:
......@@ -91,13 +89,13 @@ class AsyncWorker(Thread):
while not self.stopped and not self.queue.empty():
try:
async_item = self.queue.get(False)
self.item_number += 1
thread = Thread(target=self._run_item, args=(async_item, ))
self.running_items.append(async_item)
self.thread_sem.acquire()
async_item.process_pool = self.process_pool
self.worker_threads.append(thread)
self.item_number += 1
thread.start()
except Queue.Empty:
......@@ -128,12 +126,10 @@ class AsyncWorker(Thread):
def _run_item(self, async_item):
with ready_lock:
self.running_items.append(async_item)
async_item.run()
self.queue.task_done()
self.running_items.remove(async_item)
with ready_lock:
if not self.queue_processing and not self.running_items:
self.done = True
self.thread_sem.release()
try:
async_item.run()
self.queue.task_done()
self.running_items.remove(async_item)
finally:
self.thread_sem.release()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment