From e5d6da2ec1cb46df0b0942738f4b816d66c70fa4 Mon Sep 17 00:00:00 2001 From: mailchuck Date: Mon, 9 Nov 2015 17:15:05 +0100 Subject: [PATCH] Fix Py2Exe / Py2App Fixes the C PoW loading in frozen apps (Windows and OSX) Cleaner fallback in PoW if something goes wrong --- src/proofofwork.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/proofofwork.py b/src/proofofwork.py index f7776638..04e07af3 100644 --- a/src/proofofwork.py +++ b/src/proofofwork.py @@ -10,7 +10,12 @@ import openclpow import os import ctypes -curdir = os.path.dirname(__file__) +if frozen == "macosx_app": + curdir = os.environ.get("RESOURCEPATH") +elif frozen: # windows + curdir = sys._MEIPASS +else: + curdir = os.path.dirname(__file__) bitmsglib = 'bitmsghash.so' if "win32" == sys.platform: if ctypes.sizeof(ctypes.c_voidp) == 4: @@ -128,13 +133,18 @@ def run(target, initialHash): try: return _doGPUPoW(target, initialHash) except: - pass # fallback to normal PoW + pass # fallback + if bmpow: + try: + return _doCPoW(target, initialHash) + except: + pass # fallback if frozen == "macosx_app" or not frozen: - if bmpow: - try: - return _doCPoW(target, initialHash) - except: - pass # fallback to normal PoW - return _doFastPoW(target, initialHash) - else: - return _doSafePoW(target, initialHash) + # on my (Peter Surda) Windows 10, Windows Defender + # does not like this and fights with PyBitmessage + # over CPU, resulting in very slow PoW + try: + return _doFastPoW(target, initialHash) + except: + pass #fallback + return _doSafePoW(target, initialHash)