diff --git a/minode/proofofwork.py b/minode/proofofwork.py index c878b2a..4a63b0a 100644 --- a/minode/proofofwork.py +++ b/minode/proofofwork.py @@ -19,8 +19,13 @@ def _pow_worker(target, initial_hash, q): while trial_value > target: nonce += 1 - trial_value = struct.unpack('>Q', hashlib.sha512(hashlib.sha512( - struct.pack('>Q', nonce) + initial_hash).digest()).digest()[:8])[0] + try: + trial_value = struct.unpack('>Q', hashlib.sha512(hashlib.sha512( + struct.pack('>Q', nonce) + initial_hash + ).digest()).digest()[:8])[0] + except KeyboardInterrupt: + q.put(None) + return q.put(struct.pack('>Q', nonce)) @@ -36,6 +41,11 @@ def _worker(obj): nonce = q.get() p.join() + if nonce is None: + if not shared.shutting_down: + logging.warning('Got None nonce from _pow_worker!') + return + logging.debug( 'Finished doing POW, nonce: %s, time: %ss', nonce, time.time() - t) obj = structure.Object(