Navigation Menu

Skip to content

Commit

Permalink
support Python 3.3 (do not use ensure_future, fall back to bundled as…
Browse files Browse the repository at this point in the history
…yncio)
  • Loading branch information
mbevand committed Nov 7, 2016
1 parent c220c9f commit 62a78cf
Show file tree
Hide file tree
Showing 102 changed files with 34,251 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,4 +6,5 @@
_temp_*
*.swp
*.tmp
*.pyc
tags
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,8 +1,9 @@
# Current tip

* Add nicehash compatibility (stratum servers fixing 17 bytes of the nonce)
* Add nerdralph's optimization (OPTIM_FOR_FGLRX)
* Drop the Python 3.5 dependency; now requires only Python 3.3 or above (lhl)
* Drop the libsodium dependency; instead use our own SHA256 implementation
* Add nicehash compatibility (stratum servers fixing 17 bytes of the nonce)
* Only apply set_target to *next* mining job
* Do not abandon previous mining jobs if clean_jobs is false
* Fix KeyError's when displaying stats
Expand Down
9 changes: 4 additions & 5 deletions README.md
Expand Up @@ -121,14 +121,12 @@ Troubleshooting performance issues:
SILENTARMY has primarily been tested with AMD GPUs on 64-bit Linux with
the **AMDGPU-PRO** driver (amdgpu.ko, for newer GPUs) and the **Radeon Software
Crimson Edition** driver (fglrx.ko, for older GPUs). Its only build
dependency is an OpenCL implementation.
dependency is an OpenCL implementation. And its only runtime dependency is
Python 3.3+ (which supports SILENTARMY's use of the "yield from" syntax.)

Installation of the drivers and SDK can be error-prone, so below are
step-by-step instructions for the AMD OpenCL implementation (**AMD APP SDK**),
for Ubuntu 16.04 as well as Ubuntu 14.04 (beware: the `silentarmy` miner makes
use of Python's `ensure_future()` which requires Python 3.4.4, however Ubuntu
14.04 ships 3.4.3, therefore only the `sa-solver` tool is usable on Ubuntu
14.04.)
for Ubuntu 16.04 as well as Ubuntu 14.04.

## Ubuntu 16.04

Expand Down Expand Up @@ -261,6 +259,7 @@ Donations welcome: t1cVviFvgJinQ4w3C2m2CfRxgP5DnHYaoFC

I would like to thank these persons for their contributions to SILENTARMY,
in alphabetical order:
* lhl
* nerdralph

# License
Expand Down
32 changes: 20 additions & 12 deletions silentarmy
Expand Up @@ -9,9 +9,17 @@ import struct
import json
import binascii
import re
import asyncio
import logging

try:
import asyncio
except ImportError as e:
# system doesn't provide asyncio module (eg. Python 3.3),
# so use module bundled with silentarmy
p = os.path.join(sys.path[0], 'thirdparty', 'asyncio')
sys.path.insert(1, p) # make it the 2nd path
import asyncio

verbose_level = 0

def b2hex(b):
Expand All @@ -34,6 +42,11 @@ def very_verbose(msg):
if verbose_level > 1:
print(msg)

def my_ensure_future(coro):
loop = asyncio.get_event_loop()
task = loop.create_task(coro)
return task

def parse_url(url):
'''Return (host, port) from "stratum+tcp://host:port"'''
prefix = 'stratum+tcp://'
Expand Down Expand Up @@ -108,7 +121,7 @@ class StratumClientProtocol(asyncio.Protocol):
print('Stratum: connection was closed (invalid user/pwd?)')
else:
print('Stratum: lost connection: %s' % exc)
asyncio.ensure_future(self.sa.reconnect())
my_ensure_future(self.sa.reconnect())

#
# other methods
Expand Down Expand Up @@ -184,7 +197,7 @@ class Silentarmy:
yield from coro
except Exception as e:
print("Stratum: error connecting: %s" % e)
asyncio.ensure_future(self.reconnect())
my_ensure_future(self.reconnect())

@asyncio.coroutine
def show_stats(self):
Expand Down Expand Up @@ -259,17 +272,12 @@ class Silentarmy:
if self.opts.do_list:
self.list_devices()
self.init()
try:
asyncio.ensure_future(self.reconnect())
except AttributeError as e:
fatal(('Error calling ensure_future(): %s\n' % e) +
'Please update to Python 3.4.5 (or above) - see ' +
'https://github.com/mbevand/silentarmy/issues/8')
asyncio.ensure_future(self.show_stats())
my_ensure_future(self.reconnect())
my_ensure_future(self.show_stats())
for gpuid in self.opts.use:
for instid in range(self.opts.instances):
devid = "%d.%d" % (gpuid, instid)
asyncio.ensure_future(self.start_solvers(devid))
my_ensure_future(self.start_solvers(devid))
try:
self.loop.run_forever()
except KeyboardInterrupt as e:
Expand Down Expand Up @@ -369,7 +377,7 @@ class Silentarmy:
if devid not in self.solver_procs:
# happens if solver crashed
print('Solver %s: not running, relaunching it' % devid)
asyncio.ensure_future(self.start_solvers(devid))
my_ensure_future(self.start_solvers(devid))
# TODO: ideally the mining job should be sent to the solver
# as soon as it is back up and running
if not self.st_had_job:
Expand Down
30 changes: 30 additions & 0 deletions thirdparty/README
@@ -0,0 +1,30 @@
"asyncio" is a clone of https://github.com/python/asyncio as of revision
07ac834068037d8206d6c941e029474bda8e08f2 (03 Nov 2016) with the following
patch:

--- asyncio/base_events.py 2016-11-07 16:45:34.587238061 -0600
+++ asyncio/base_events.py 2016-11-07 14:50:34.169035083 -0600
@@ -40,6 +40,11 @@

__all__ = ['BaseEventLoop']

+# lhl: We need to add this back in because 3.3 doesn't have a default max_workers in ThreadPoolExecuter
+# https://bugs.python.org/issue26796
+# https://docs.python.org/3/library/asyncio-eventloop.html#executor
+# https://docs.python.org/3/library/concurrent.futures.html
+_MAX_WORKERS=8

# Minimum number of _scheduled timer handles before cleanup of
# cancelled handles is performed.
@@ -619,7 +624,10 @@
if executor is None:
executor = self._default_executor
if executor is None:
- executor = concurrent.futures.ThreadPoolExecutor()
+ try:
+ executor = concurrent.futures.ThreadPoolExecutor()
+ except:
+ executor = concurrent.futures.ThreadPoolExecutor(_MAX_WORKERS)
self._default_executor = executor
return futures.wrap_future(executor.submit(func, *args), loop=self)

2 changes: 2 additions & 0 deletions thirdparty/asyncio/.gitattributes
@@ -0,0 +1,2 @@
* text=auto
*.py text diff=python
18 changes: 18 additions & 0 deletions thirdparty/asyncio/.gitignore
@@ -0,0 +1,18 @@
*\.py[co]
*~
*\.orig
*\#.*
*@.*
.coverage
htmlcov
.DS_Store
venv
pyvenv
distribute_setup.py
distribute-*.tar.gz
build
dist
*.egg-info
.tox
.idea/
*.iml
15 changes: 15 additions & 0 deletions thirdparty/asyncio/.travis.yml
@@ -0,0 +1,15 @@
language: python

os:
- linux

python:
- 3.5

install:
- pip install asyncio
- python setup.py install

script:
- python runtests.py
- PYTHONASYNCIODEBUG=1 python -bb runtests.py
27 changes: 27 additions & 0 deletions thirdparty/asyncio/AUTHORS
@@ -0,0 +1,27 @@
A. Jesse Jiryu Davis <jesse AT mongodb.com>
Aaron Griffith
Andrew Svetlov <andrew.svetlov AT gmail.com>
Anthony Baire
Antoine Pitrou <solipsis AT pitrou.net>
Arnaud Faure
Aymeric Augustin
Brett Cannon
Charles-François Natali <cf.natali AT gmail.com>
Christian Heimes
Donald Stufft
Eli Bendersky <eliben AT gmail.com>
Geert Jansen <geertj AT gmail.com>
Giampaolo Rodola' <g.rodola AT gmail.com>
Guido van Rossum <guido AT python.org>: creator of the asyncio project and author of the PEP 3156
Gustavo Carneiro <gjcarneiro AT gmail.com>
Jeff Quast
Jonathan Slenders <jonathan.slenders AT gmail.com>
Nikolay Kim <fafhrd91 AT gmail.com>
Richard Oudkerk <shibturn AT gmail.com>
Saúl Ibarra Corretgé <saghul AT gmail.com>
Serhiy Storchaka
Vajrasky Kok
Victor Stinner <victor.stinner AT gmail.com>
Vladimir Kryachko
Yann Sionneau
Yury Selivanov <yselivanov AT gmail.com>

0 comments on commit 62a78cf

Please sign in to comment.