-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (47 loc) · 1.77 KB
/
main.py
File metadata and controls
61 lines (47 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import asyncio
from time import sleep
import janus
import os
import health_reader
import share_reader
import websocket_client
from helpers import print_subprocess, run_with_sudo
from base_logger import logger
from dotenv import load_dotenv
load_dotenv()
logger = logger.getLogger(__name__)
async def run():
queue = janus.Queue()
logger.info('Resetting overclocks')
print_subprocess(f"echo {os.getenv('SUDO_PASS')} | sudo -S ./reset-oc")
logger.info('Configuring power limits')
print_subprocess(f"echo {os.getenv('SUDO_PASS')} | sudo -S ./config-gpus")
logger.info('Setting fan speeds')
print_subprocess(f"echo {os.getenv('SUDO_PASS')} | sudo -S ./fan-gpus")
loop.run_in_executor(None, share_reader.start_mining, queue.sync_q)
loop.run_in_executor(None, delayed_overclock())
await asyncio.gather(websocket_client.connect_server(),
rerun_on_exception(share_reader.consume, queue.async_q),
rerun_on_exception(websocket_client.run),
rerun_on_exception(health_reader.query_all_health),
)
def delayed_overclock():
# wait for the dag to be generated before overclocking
sleep(45)
logger.info('Overclocking GPUs')
run_with_sudo("./oc-gpus")
async def rerun_on_exception(coro, *args, **kwargs):
while True:
try:
logger.warning('running coroutine again...')
await coro(*args, **kwargs)
except asyncio.CancelledError:
# don't interfere with cancellations
raise
except Exception as e:
logger.error(e, exc_info=True)
# traceback.print_exc()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
loop.close()