From e4861c027247e63eb6abede94c9a1fe7e9317b2c Mon Sep 17 00:00:00 2001 From: Death916 Date: Thu, 13 Feb 2020 12:09:31 -0800 Subject: [PATCH] check if miner is running --- minestart.py | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/minestart.py b/minestart.py index 9cc65c4..a6f2341 100644 --- a/minestart.py +++ b/minestart.py @@ -3,29 +3,61 @@ import GPUtil as gpu import time - +import psutil def checkgpu(): card = gpu.getGPUs() isavailable = gpu.getAvailability(card, maxLoad=.6) - + print(time.ctime()) if isavailable == [1]: print("can mine") - print(time.ctime()) - time.sleep(1) + time.sleep(5) + return 'isavailable' if isavailable == [0]: print("cant mine") - print(time.ctime()) - time.sleep(1) - return isavailable + time.sleep(5) + return 'notavailable' + + + +def findProcessIdByName(processName): + + listOfProcessObjects = [] + + # Iterate over the all the running process + for proc in psutil.process_iter(): + try: + pinfo = proc.as_dict(attrs=['pid', 'name', 'create_time']) + # Check if process name contains the given name string. + if processName.lower() in pinfo['name'].lower(): + listOfProcessObjects.append(pinfo) + except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): + pass + + return listOfProcessObjects; + def checkminer(): + minercheck = findProcessIdByName('ccminer.exe') + if minercheck == []: + return 'notrunning' + else: + return "running" + + while True: - - isavailable() + gpus = checkgpu() + miner = checkminer() + if gpus is 'isavailable' and miner is 'notrunning': + print('can start miner') + else: + print('cant start miner') + + +