Support the PoW interruption

This commit is contained in:
Lee Miller 2024-09-25 04:05:49 +03:00
parent 5f0ab21268
commit db199248ef
Signed by: lee.miller
GPG Key ID: 4F97A5EA88F4AB63

View File

@ -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(