Support the PoW interruption
This commit is contained in:
parent
5f0ab21268
commit
db199248ef
|
@ -19,8 +19,13 @@ def _pow_worker(target, initial_hash, q):
|
||||||
|
|
||||||
while trial_value > target:
|
while trial_value > target:
|
||||||
nonce += 1
|
nonce += 1
|
||||||
|
try:
|
||||||
trial_value = struct.unpack('>Q', hashlib.sha512(hashlib.sha512(
|
trial_value = struct.unpack('>Q', hashlib.sha512(hashlib.sha512(
|
||||||
struct.pack('>Q', nonce) + initial_hash).digest()).digest()[:8])[0]
|
struct.pack('>Q', nonce) + initial_hash
|
||||||
|
).digest()).digest()[:8])[0]
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
q.put(None)
|
||||||
|
return
|
||||||
|
|
||||||
q.put(struct.pack('>Q', nonce))
|
q.put(struct.pack('>Q', nonce))
|
||||||
|
|
||||||
|
@ -36,6 +41,11 @@ def _worker(obj):
|
||||||
nonce = q.get()
|
nonce = q.get()
|
||||||
p.join()
|
p.join()
|
||||||
|
|
||||||
|
if nonce is None:
|
||||||
|
if not shared.shutting_down:
|
||||||
|
logging.warning('Got None nonce from _pow_worker!')
|
||||||
|
return
|
||||||
|
|
||||||
logging.debug(
|
logging.debug(
|
||||||
'Finished doing POW, nonce: %s, time: %ss', nonce, time.time() - t)
|
'Finished doing POW, nonce: %s, time: %ss', nonce, time.time() - t)
|
||||||
obj = structure.Object(
|
obj = structure.Object(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user