diff --git a/README.md b/README.md index 3456de08..67bb20a9 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,21 @@ if __name__ == '__main__': 2. Navigate to this directory, and run ```make_cfg_tool_exe.py build``` on Windows or ```python3 make_cfg_tool_exe.py``` on Mac or UNIX. ### Interfacing with miners programmatically +
+ +##### Note: If you are trying to interface with Whatsminers, there is a bug in the way they are interacted with on Windows, so to fix that you need to change the event loop policy using this code: +```python +# need to import these 2 libraries, you need asyncio anyway so make sure you have sys imported +import sys +import asyncio + +# if the computer is windows, set the event loop policy to a WindowsSelector policy +if sys.version_info[0] == 3 and sys.version_info[1] >= 8 and sys.platform.startswith('win'): + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) +``` + +##### It is likely a good idea to use this code in your program anyway to be preventative. +
To write your own custom programs with this repo, you have many options. diff --git a/cfg_util/miner_factory.py b/cfg_util/miner_factory.py index 8b1647f2..fa9bb953 100644 --- a/cfg_util/miner_factory.py +++ b/cfg_util/miner_factory.py @@ -1,3 +1,7 @@ +""" +This file stores the MinerFactory instance used by the ConfigUtility for use in other files. +""" + from miners.miner_factory import MinerFactory miner_factory = MinerFactory() diff --git a/miners/miner_factory.py b/miners/miner_factory.py index 5ea87c2c..0ae509e6 100644 --- a/miners/miner_factory.py +++ b/miners/miner_factory.py @@ -16,6 +16,14 @@ class MinerFactory: self.miners = {} async def get_miner_generator(self, ips: list): + """ + Get Miner objects from ip addresses using an async generator. + + Returns an asynchronous generator containing Miners. + + Parameters: + ips: a list of ip addresses to get miners for. + """ loop = asyncio.get_event_loop() scan_tasks = [] for miner in ips: diff --git a/network/__init__.py b/network/__init__.py index a7e93c3c..1ea1d1b3 100644 --- a/network/__init__.py +++ b/network/__init__.py @@ -31,7 +31,7 @@ class MinerNetwork: return ipaddress.ip_network(f"{default_gateway}/{subnet_mask}", strict=False) async def scan_network_for_miners(self) -> None or list: - """Scan the network for miners, and """ + """Scan the network for miners, and return found miners as a list.""" local_network = self.get_network() print(f"Scanning {local_network} for miners...") scan_tasks = [] @@ -55,6 +55,11 @@ class MinerNetwork: return miners async def scan_network_generator(self): + """ + Scan the network for miners using an async generator. + + Returns an asynchronous generator containing found miners. + """ loop = asyncio.get_event_loop() local_network = self.get_network() scan_tasks = []