[diffoscope] 03/06: parallel: added thread_manager
Juliana Oliveira
jwnx-guest at moszumanska.debian.org
Tue Jan 9 05:04:26 CET 2018
This is an automated email from the git hooks/post-receive script.
jwnx-guest pushed a commit to branch jwnx_parallel_diffoscope
in repository diffoscope.
commit 644d3c1092fd66a0b5f3c20cce4c6ccfa23107f5
Author: Juliana Oliveira <juliana.orod at gmail.com>
Date: Tue Jan 9 00:57:03 2018 -0200
parallel: added thread_manager
---
diffoscope/parallel/thread_manager.py | 48 +++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/diffoscope/parallel/thread_manager.py b/diffoscope/parallel/thread_manager.py
new file mode 100644
index 0000000..e7b6371
--- /dev/null
+++ b/diffoscope/parallel/thread_manager.py
@@ -0,0 +1,48 @@
+from threading import Thread
+from queue import Queue
+
+
+class ThreadManager(object):
+
+ def __init__(self):
+ self._size = 0
+ self._threads = []
+ self._queue = Queue()
+
+
+ def start(self):
+ if not self._threads:
+ return
+ for thr in self._threads:
+ thr.start()
+
+
+ def ready(self):
+ for thr in self._threads:
+ if thr.is_alive():
+ return False
+ return True
+
+
+ def join(self):
+ self._queue.join()
+
+ for thr in self._threads:
+ thr.join()
+
+
+ def result(self):
+ result = []
+ while not self._queue.empty():
+ result.append(self._queue.get())
+
+ return result
+
+
+ def new(self, fun, args):
+ thr = Thread(target=lambda q, f, ar: q.put(f(ar)),
+ args=(self._queue, fun, args))
+
+ thr.start()
+ self._threads.append(thr)
+ self._size += 1
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list