Support green threads, run coverage with py27

This commit is contained in:
Davanum Srinivas 2017-03-27 21:21:41 -04:00
parent 04151e9df8
commit 9ccbbec8b7
4 changed files with 32 additions and 6 deletions

View File

@ -9,9 +9,9 @@ env:
- TOXENV=pypy-etcd
- TOXENV=py27
- TOXENV=py27-etcd
- TOXENV=py27-codecov
- TOXENV=py35
- TOXENV=py35-etcd
- TOXENV=codecov
- TOXENV=docs
- TOXENV=examples
- TOXENV=releasenotes

View File

@ -11,7 +11,9 @@
# under the License.
import base64
import sys
import futurist
import six
bytes_types = (bytes, bytearray)
@ -57,3 +59,27 @@ def _increment_last_byte(data):
DEFAULT_TIMEOUT = 30
LOCK_PREFIX = '/locks/'
def _import_module(import_str):
"""Import a module."""
__import__(import_str)
return sys.modules[import_str]
def _try_import(import_str, default=None):
"""Try to import a module and if it fails return default."""
try:
return _import_module(import_str)
except ImportError:
return default
# These may or may not exist; so carefully import them if we can...
_eventlet = _try_import('eventlet')
_patcher = _try_import('eventlet.patcher')
def _get_threadpool_executor():
if all((_eventlet, _patcher)) and _patcher.is_monkey_patched('thread'):
return futurist.GreenThreadPoolExecutor
return futurist.ThreadPoolExecutor

View File

@ -12,10 +12,9 @@
import json
import futurist
from etcd3gw.utils import _decode
from etcd3gw.utils import _encode
from etcd3gw.utils import _get_threadpool_executor
class WatchTimedOut(Exception):
@ -62,7 +61,8 @@ class Watcher(object):
json=create_request,
stream=True)
self._executor = futurist.ThreadPoolExecutor(max_workers=2)
clazz = _get_threadpool_executor()
self._executor = clazz(max_workers=2)
self._executor.submit(_watch, self._response, callback)
def stop(self):

View File

@ -21,12 +21,12 @@ commands = flake8 {posargs}
[testenv:venv]
commands = {posargs}
[testenv:cover]
[testenv:py27-cover]
commands =
coverage erase
python setup.py test --coverage --testr-args='{posargs}'
[testenv:codecov]
[testenv:py27-codecov]
commands =
{toxinidir}/setup-etcd-env.sh pifpaf -g TOOZ_TEST run etcd -- nosetests --with-coverage --cover-package=etcd3gw --cover-tests
codecov