[ocrfeeder/new_fixes: 10/10] fix a race condition in parallel recognizion
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ocrfeeder/new_fixes: 10/10] fix a race condition in parallel recognizion
- Date: Mon, 1 Oct 2012 19:51:38 +0000 (UTC)
commit fbb75c31f0fb79fcff4228dfaf85f6d8b8734e8c
Author: Jan Losinski <losinski wh2 tu-dresden de>
Date: Fri Jul 27 18:14:04 2012 +0200
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: Jan Losinski <losinski wh2 tu-dresden de>
src/ocrfeeder/studio/widgetModeler.py | 2 +-
src/ocrfeeder/util/asyncworker.py | 20 ++++++++------------
2 files changed, 9 insertions(+), 13 deletions(-)
---
diff --git a/src/ocrfeeder/studio/widgetModeler.py b/src/ocrfeeder/studio/widgetModeler.py
index e5b7887..67bc296 100644
--- a/src/ocrfeeder/studio/widgetModeler.py
+++ b/src/ocrfeeder/studio/widgetModeler.py
@@ -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
diff --git a/src/ocrfeeder/util/asyncworker.py b/src/ocrfeeder/util/asyncworker.py
index ffee92f..c031322 100644
--- a/src/ocrfeeder/util/asyncworker.py
+++ b/src/ocrfeeder/util/asyncworker.py
@@ -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()
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]