From 12e08a6f643244d1950336eb0fcb4da04869f2c4 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Tue, 21 Jul 2020 23:59:25 +0200 Subject: [PATCH] Add selectors34 fallback for py27 under 64-bit Win This change addresses a bug in selectors2 (that is resolved in master but is unreleased) with fd of the "long" type not being recognized as "int". Here's the traceback it causes: Traceback (most recent call last): File "C:\projects\cheroot\cheroot\server.py", line 1788, in serve self.tick() File "C:\projects\cheroot\cheroot\server.py", line 2023, in tick conn = self.connections.get_conn(self.socket) File "C:\projects\cheroot\cheroot\connections.py", line 163, in get_conn self._selector.unregister(fno) File "c:\projects\cheroot\.tox\python\lib\site-packages\selectors2.py", line 249, in unregister key = super(SelectSelector, self).unregister(fileobj) File "c:\projects\cheroot\.tox\python\lib\site-packages\selectors2.py", line 155, in unregister key = self._fd_to_key.pop(self._fileobj_lookup(fileobj)) File "c:\projects\cheroot\.tox\python\lib\site-packages\selectors2.py", line 127, in _fileobj_lookup return _fileobj_to_fd(fileobj) File "c:\projects\cheroot\.tox\python\lib\site-packages\selectors2.py", line 90, in _fileobj_to_fd raise ValueError("Invalid file object: {0!r}".format(fileobj)) ValueError: Invalid file object: 916L Refs: * https://github.com/sethmlarson/selectors2/pull/10 * https://twitter.com/webKnjaZ/status/1285695028136992769 * https://github.com/berkerpeksag/selectors34/blob/1.2.0/selectors34.py#L51 * https://github.com/cherrypy/cheroot/pull/301#issuecomment-662127125 --- cheroot/_compat.py | 6 +++++- setup.cfg | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cheroot/_compat.py b/cheroot/_compat.py index 7f7a380a1a..f879e5eee6 100644 --- a/cheroot/_compat.py +++ b/cheroot/_compat.py @@ -1,3 +1,4 @@ +# pylint: disable=unused-import """Compatibility code for using Cheroot with various versions of Python.""" from __future__ import absolute_import, division, print_function @@ -11,7 +12,10 @@ try: import selectors # lgtm [py/unused-import] except ImportError: - import selectors2 as selectors # noqa: F401 # lgtm [py/unused-import] + try: + import selectors2 as selectors # noqa: F401 # lgtm [py/unused-import] + except ImportError: + import selectors34 as selectors # noqa: F401 # lgtm [py/unused-import] try: import ssl diff --git a/setup.cfg b/setup.cfg index cf2df16f9a..e56717d9e1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -65,7 +65,8 @@ setup_requires = # These are required in actual runtime: install_requires = backports.functools_lru_cache; python_version < '3.3' - selectors2; python_version< '3.4' + selectors2; python_version < '3.4' and (sys_platform != "win32" or (sys_platform == "win32" and python_version >= '3.0')) + selectors34; python_version < '3.0' and sys_platform == "win32" six>=1.11.0 more_itertools>=2.6 jaraco.functools