Commit 88663a4a authored by Jason Madden's avatar Jason Madden

Patch selectors on Python 3.4. Fixes #591

parent 41bf3e23
...@@ -17,7 +17,8 @@ Unreleased ...@@ -17,7 +17,8 @@ Unreleased
``gevent.pool.Group``/``Pool`` and the builtin ``apply`` function. ``gevent.pool.Group``/``Pool`` and the builtin ``apply`` function.
This obsoletes the undocumented ``apply_e`` function. Original PR This obsoletes the undocumented ``apply_e`` function. Original PR
#556 by Robert Estelle. #556 by Robert Estelle.
- Monkey-patch the ``selectors`` module from ``patch_all`` and
``patch_select`` on Python 3.4. See #591.
1.1a1 (Jun 29, 2015) 1.1a1 (Jun 29, 2015)
==================== ====================
......
...@@ -204,7 +204,8 @@ def patch_ssl(): ...@@ -204,7 +204,8 @@ def patch_ssl():
def patch_select(aggressive=True): def patch_select(aggressive=True):
"""Replace :func:`select.select` with :func:`gevent.select.select`. """Replace :func:`select.select` with :func:`gevent.select.select`.
If aggressive is true (the default), also remove other blocking functions the :mod:`select`. If ``aggressive`` is true (the default), also remove other blocking functions from :mod:`select`
and (on Python 3.4 and above) :mod:`selectors`.
""" """
patch_module('select') patch_module('select')
if aggressive: if aggressive:
...@@ -219,7 +220,8 @@ def patch_select(aggressive=True): ...@@ -219,7 +220,8 @@ def patch_select(aggressive=True):
if sys.version_info[:2] >= (3, 4): if sys.version_info[:2] >= (3, 4):
# Python 3 wants to use `select.select` as a member function, # Python 3 wants to use `select.select` as a member function,
# leading to this error in selectors.py # leading to this error in selectors.py (because gevent.select.select is
# not a builtin and doesn't get the magic auto-static that they do)
# r, w, _ = self._select(self._readers, self._writers, [], timeout) # r, w, _ = self._select(self._readers, self._writers, [], timeout)
# TypeError: select() takes from 3 to 4 positional arguments but 5 were given # TypeError: select() takes from 3 to 4 positional arguments but 5 were given
select = __import__('select') select = __import__('select')
...@@ -229,6 +231,15 @@ def patch_select(aggressive=True): ...@@ -229,6 +231,15 @@ def patch_select(aggressive=True):
return select.select(*args, **kwargs) return select.select(*args, **kwargs)
selectors.SelectSelector._select = _select selectors.SelectSelector._select = _select
if aggressive:
# If `selectors` had already been imported before we removed
# select.poll|epoll|kqueue, these may have been defined in terms
# of those functions. They'll fail at runtime.
remove_item(selectors, 'PollSelector')
remove_item(selectors, 'EpollSelector')
remove_item(selectors, 'KqueueSelector')
selectors.DefaultSelector = selectors.SelectSelector
def patch_subprocess(): def patch_subprocess():
patch_module('subprocess') patch_module('subprocess')
......
This diff is collapsed.
...@@ -21,7 +21,8 @@ def get_absolute_pythonpath(): ...@@ -21,7 +21,8 @@ def get_absolute_pythonpath():
def TESTRUNNER(tests=None): def TESTRUNNER(tests=None):
if not os.path.exists(directory): if not os.path.exists(directory):
return return
preferred_version = open(os.path.join(directory, 'version')).read().strip() with open(os.path.join(directory, 'version')) as f:
preferred_version = f.read().strip()
if preferred_version != version: if preferred_version != version:
util.log('WARNING: The tests in %s/ are from version %s and your Python is %s', directory, preferred_version, version) util.log('WARNING: The tests in %s/ are from version %s and your Python is %s', directory, preferred_version, version)
......
...@@ -24,7 +24,7 @@ RUN_ALONE = [ ...@@ -24,7 +24,7 @@ RUN_ALONE = [
] ]
def run_many(tests, expected=None, failfast=False): def run_many(tests, expected=(), failfast=False):
global NWORKERS global NWORKERS
start = time.time() start = time.time()
total = 0 total = 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment