From da0b771e358fdc2539c9537c7f94871c78ffdd0b Mon Sep 17 00:00:00 2001 From: Arceliar Date: Thu, 30 May 2013 17:38:02 +0200 Subject: [PATCH] Workers get idle priority. --- src/proofofwork.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/proofofwork.py b/src/proofofwork.py index 03d7c22d..d8140707 100644 --- a/src/proofofwork.py +++ b/src/proofofwork.py @@ -1,6 +1,21 @@ +def _set_idle(): + import sys + try: + sys.getwindowsversion() + import win32api,win32process,win32con + pid = win32api.GetCurrentProcessId() + handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid) + win32process.SetPriorityClass(handle, win32process.IDLE_PRIORITY_CLASS) + except: + import os + os.nice(20) + def _pool_worker(nonce, initialHash, target, pool_size): import hashlib + import sys + import os from struct import unpack, pack + _set_idle() trialValue = 99999999999999999999 while trialValue > target: nonce += pool_size @@ -8,7 +23,7 @@ def _pool_worker(nonce, initialHash, target, pool_size): return [trialValue, nonce] def run(target, initialHash): - from multiprocessing import Pool, cpu_count + from multiprocessing import Pool, cpu_count, Value import time try: pool_size = cpu_count() @@ -25,4 +40,3 @@ def run(target, initialHash): pool.terminate() return result[0], result[1] time.sleep(1) -