[Reproducible-commits] [diffoscope] 11/21: Switch to thread based multiprocessing to run diff

Jérémy Bobbio lunar at moszumanska.debian.org
Mon Sep 21 17:39:27 UTC 2015


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch master
in repository diffoscope.

commit 85629f54c4836a6f9ebb1858d31eefbcf1276892
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Sat Sep 19 23:13:50 2015 +0200

    Switch to thread based multiprocessing to run diff
    
    We don't gain much by forking new processes to feed input to diff. So let's
    use the thread based version of multiprocessing.
    
    This allows to simplify exception handling as they can now be passed directly
    instead of going through pickle and its limitations. We can also lift the
    requierment on having /dev/shm available.
    
    After some tests, performance seems to be as good as they were before.
---
 diffoscope/difference.py | 30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)

diff --git a/diffoscope/difference.py b/diffoscope/difference.py
index a1ef393..879d917 100644
--- a/diffoscope/difference.py
+++ b/diffoscope/difference.py
@@ -26,7 +26,7 @@ import subprocess
 import sys
 import traceback
 from threading import Thread
-from multiprocessing import Queue
+from multiprocessing.dummy import Queue
 from diffoscope.config import Config
 from diffoscope import logger, tool_required, RequiredToolNotFound
 
@@ -170,26 +170,20 @@ class ExThread(Thread):
     def run(self, *args, **kwargs):
         try:
             super(ExThread, self).run(*args, **kwargs)
-        except Exception:
-            except_type, except_class, tb = sys.exc_info()
-            self.__status_queue.put((except_type, except_class, traceback.extract_tb(tb)))
+        except Exception as ex:
+            #except_type, except_class, tb = sys.exc_info()
+            self.__status_queue.put(ex)
         self.__status_queue.put(None)
 
     def wait_for_exc_info(self):
         return self.__status_queue.get()
 
     def join(self):
-        ex_info = self.wait_for_exc_info()
-        if ex_info is None:
+        ex = self.wait_for_exc_info()
+        if ex is None:
             return
         else:
-            except_type, except_class, tb = ex_info
-            logger.error('Exception: %s',
-                         traceback.format_exception_only(except_type, except_class)[0].strip())
-            logger.error('Traceback:')
-            for line in traceback.format_list(tb):
-                logger.error(line[:-1])
-            raise except_type(except_class)
+            raise ex
 
 
 def feed(feeder, f, end_nl_q):
@@ -258,14 +252,8 @@ def make_feeder_from_command(command):
 
 
 def diff(feeder1, feeder2):
-    try:
-        end_nl_q1 = Queue()
-        end_nl_q2 = Queue()
-    except OSError as e:
-        if e.errno not in (13, 38):
-            raise
-        logger.critical('/dev/shm is not available or not on a tmpfs. Unable to create semaphore.')
-        sys.exit(2)
+    end_nl_q1 = Queue()
+    end_nl_q2 = Queue()
     with fd_from_feeder(feeder1, end_nl_q1) as fd1:
         with fd_from_feeder(feeder2, end_nl_q2) as fd2:
             return run_diff(fd1, fd2, end_nl_q1, end_nl_q2)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git



More information about the Reproducible-commits mailing list