Skip to content

Instantly share code, notes, and snippets.

@mtisz
Last active October 22, 2021 04:53
Show Gist options
  • Save mtisz/e7d79a3e9d067355cf9a7bf29c147b3c to your computer and use it in GitHub Desktop.
Save mtisz/e7d79a3e9d067355cf9a7bf29c147b3c to your computer and use it in GitHub Desktop.
A Python 3 script to run an Ethereum miner with self-monitoring and self-restart
import subprocess as sp
import logging
from abc import ABC
import time
from concurrent.futures import ThreadPoolExecutor
"""
Your terminal command goes here
"""
ETH_CMD = "/home/ethminer/bin/ethminer -P stratum1+ssl://<ETH_ADD>.MINER@us2.ethermine.org:5555"
class StartMiner(ABC):
def __init__(self):
def __minecrypto__(cmd):
process = sp.run(cmd.split())
thread_pool = ThreadPoolExecutor(max_workers=1)
threads = []
threads.append(thread_pool.submit(__minecrypto__, ETH_CMD))
logging.info("Miner Started")
# Monitoring the threads every half a second
while True:
for pp in range(len(threads)):
if threads[pp].running() == False:
threads[pp] = thread_pool.submit(__minecrypto__, ETH_CMD)
logging.info("Thread %s restarted" % (str(pp)))
time.sleep(0.5)
thread_pool.shutdown(wait=True)
if __name__=='__main__':
StartMiner()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment