kill miner on game start

This commit is contained in:
Death916 2020-03-04 16:20:36 -08:00
parent ffdc2dc4c1
commit 07c66a6add

View file

@ -1,10 +1,11 @@
"""" restart miner when gpu is low usage and kill miner if already running """" restart miner when gpu is low usage and kill miner if already running
""" """
import GPUtil as gpu
import time import time
import psutil
from subprocess import CREATE_NEW_CONSOLE from subprocess import CREATE_NEW_CONSOLE
import GPUtil as gpu
import keyboard
import psutil
gameList = {"gears": "gears5.exe", gameList = {"gears": "gears5.exe",
"outer_worlds": "IndianaWindowsStore-Win64-Shipping.exe", "outer_worlds": "IndianaWindowsStore-Win64-Shipping.exe",
@ -14,7 +15,6 @@ gameList = {"gears": "gears5.exe",
} }
def checkgpu(): def checkgpu():
card = gpu.getGPUs() card = gpu.getGPUs()
isavailable = gpu.getAvailability(card, maxLoad=.6) isavailable = gpu.getAvailability(card, maxLoad=.6)
@ -27,7 +27,7 @@ def checkgpu():
if isavailable == [0]: if isavailable == [0]:
print("gpu in use") print("gpu in use")
gpu.showUtilization() gpu.showUtilization()
time.sleep(500) time.sleep(5)
return 'notavailable' return 'notavailable'
@ -63,23 +63,25 @@ def killminer():
def startminer(): def startminer():
keyboard.press_and_release('alt+x')
psutil.Popen(['E:/downloads/ccminer.bat'], creationflags=CREATE_NEW_CONSOLE) psutil.Popen(['E:/downloads/ccminer.bat'], creationflags=CREATE_NEW_CONSOLE)
def checkgames(): def checkgames():
game = 0 game = 0
for i in gameList.values(): for i in gameList.values():
game = findProcessIdByName(i) game = findProcessIdByName(i)
if game == []: if game:
print(i + " is not running") print("game is running")
pass
else:
print(i + " is running" )
print(game) print(game)
killminer() miners = checkminer()
if miners == 'running':
killminer()
keyboard.press_and_release('alt+y')
return 'gamerunning'
else:
return 'nogame'
@ -91,16 +93,19 @@ def checkgames():
""" """
curTime = time.time() curTime = time.time()
while True: while True:
checkgames()
gpus = checkgpu() gpus = checkgpu()
miner = checkminer() miner = checkminer()
checkgames()
usage = str(gpu.showUtilization()) usage = str(gpu.showUtilization())
#log(str(gpu.showUtilization())) #log(str(gpu.showUtilization()))
if gpus is 'isavailable' and miner is 'notrunning': if gpus is 'isavailable' and miner is 'notrunning':
print('starting miner') x = checkgames()
startminer() if x != 'gamerunning':
time.sleep(120) print('starting miner')
startminer()
time.sleep(120)
if gpus is 'isavailable' and miner is 'running': if gpus is 'isavailable' and miner is 'running':
killminer() killminer()
@ -113,4 +118,6 @@ while True:
time.sleep(10) time.sleep(10)
##TODO:check for games running probably best way is to make a list of all games and check against list ##TODO:check temp
#TODO: if no network kill and wait