summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdigest.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/digest.py b/digest.py
index 19218a8..4671467 100755
--- a/digest.py
+++ b/digest.py
@@ -7,7 +7,12 @@
from __future__ import print_function
import hashlib
import sys
-from multiprocessing import Process, Queue
+from threading import Thread
+try:
+ from queue import Queue
+except:
+ # Python 2 compatibility
+ from Queue import Queue
def read_blocks(filename):
if filename == '-':
@@ -53,7 +58,7 @@ class MtHasher(Hasher):
self._queues = {}
self._threads = {}
for algo in algos:
- t = Process(target=self._queue_updater, args=(algo,), name=algo)
+ t = Thread(target=self._queue_updater, args=(algo,), name=algo)
self._queues[algo] = Queue(MtHasher.QUEUE_SIZE)
self._threads[algo] = t
t.start()
@@ -67,8 +72,6 @@ class MtHasher(Hasher):
if not data:
break
h.update(data)
- # Runs on a different process, so need to signal the result
- q.put(h.hexdigest())
def update(self, data):
if data:
@@ -81,10 +84,8 @@ class MtHasher(Hasher):
q = self._queues[algo]
q.put(b'') # Terminate
self._threads[algo].join()
- digest = q.get_nowait()
assert q.empty()
- q.close()
- yield algo, digest
+ return super(MtHasher, self).hexdigests()
try:
supported_algos = hashlib.algorithms_guaranteed