Commit d099423c authored by Jason Madden's avatar Jason Madden

Fix tests on windows, where SelectSelector._select is a normal method.

parent 3d4404d2
......@@ -28,14 +28,17 @@ else:
try:
from select import poll as original_poll
from select import POLLIN, POLLOUT, POLLNVAL
__implements__ = ['select', 'poll']
except ImportError:
original_poll = None
POLLIN = 1
POLLOUT = 4
POLLNVAL = 32
__implements__ = ['select']
__all__ = ['error'] + __implements__
if 'poll' not in __all__:
__all__.append('poll')
import select as __select__
......@@ -184,8 +187,8 @@ def select(rlist, wlist, xlist, timeout=None): # pylint:disable=unused-argument
return result.select(rlist, wlist, timeout)
if original_poll is not None:
class PollResult(object):
class PollResult(object):
__slots__ = ('events', 'event')
def __init__(self):
......@@ -205,13 +208,17 @@ if original_poll is not None:
self.events.add((fd, result_flags))
self.event.set()
class poll(object):
class poll(object):
"""
An implementation of :class:`select.poll` that blocks only the current greenlet.
.. caution:: ``POLLPRI`` data is not supported.
.. versionadded:: 1.1b1
.. versionchanged:: 1.5
This is now always defined, regardless of whether the standard library
defines :func:`select.poll` or not. Note that it may have different performance
characteristics.
"""
def __init__(self):
# {int -> flags}
......@@ -298,8 +305,6 @@ if original_poll is not None:
fileno = get_fileno(fd)
del self.fds[fileno]
del original_poll
def _gevent_do_monkey_patch(patch_request):
aggressive = patch_request.patch_kwargs['aggressive']
......@@ -323,13 +328,19 @@ def _gevent_do_monkey_patch(patch_request):
# package? If so, must be careful to deal with DoNotPatch exceptions.
# Python 3 wants to use `select.select` as a member function,
# 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)
# 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)
# TypeError: select() takes from 3 to 4 positional arguments but 5 were given
# Note that this obviously only happens if selectors was imported after we had patched
# select; but there is a code path that leads to it being imported first (but now we've
# patched select---so we can't compare them identically)
#
# Note that this obviously only happens if selectors was
# imported after we had patched select; but there is a code
# path that leads to it being imported first (but now we've
# patched select---so we can't compare them identically). It also doesn't
# happen on Windows, because they define a normal method for _select, to work around
# some weirdness in the handling of the third argument.
orig_select_select = patch_request.get_original('select', 'select')
assert target_mod.select is not orig_select_select
......
......@@ -21,6 +21,9 @@ patch_all()
)
class TestSelectors(greentest.TestCase):
@greentest.skipOnWindows(
"SelectSelector._select is a normal function on Windows"
)
def test_selectors_select_is_patched(self):
# https://github.com/gevent/gevent/issues/835
_select = selectors.SelectSelector._select
......
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