Skip to content

Commit

Permalink
Add selectors34 fallback for py27 under 64-bit Win
Browse files Browse the repository at this point in the history
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:
  * sethmlarson/selectors2#10
  * https://twitter.com/webKnjaZ/status/1285695028136992769
  * https://github.com/berkerpeksag/selectors34/blob/1.2.0/selectors34.py#L51
  * #301 (comment)
  • Loading branch information
webknjaz committed Jul 21, 2020
1 parent 7b54965 commit 12e08a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cheroot/_compat.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 12e08a6

Please sign in to comment.