Mercurial > public > mercurial-scm > hg
comparison mercurial/selectors2.py @ 34639:a568a46751b6
selectors2: do not use platform.system()
`platform.system()` may have a side effect spawning a shell executing
`uname -p`, which may print a warning when the current directory is removed:
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
This patch changes selectors2 to test the `sys.platform` string, which is a
much safer way to detect Jython.
Jython's `sys.platform` looks like this:
Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43)
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.8.0_144
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.platform
'java1.8.0_144 ( ==linux2 for targets )'
Differential Revision: https://phab.mercurial-scm.org/D1018
author | Jun Wu <quark@fb.com> |
---|---|
date | Wed, 11 Oct 2017 17:27:21 -0700 |
parents | 5d0c0c8d2929 |
children |
comparison
equal
deleted
inserted
replaced
34638:021607b4ef49 | 34639:a568a46751b6 |
---|---|
27 from __future__ import absolute_import | 27 from __future__ import absolute_import |
28 | 28 |
29 import collections | 29 import collections |
30 import errno | 30 import errno |
31 import math | 31 import math |
32 import platform | |
33 import select | 32 import select |
34 import socket | 33 import socket |
35 import sys | 34 import sys |
36 import time | 35 import time |
36 | |
37 from . import pycompat | |
37 | 38 |
38 namedtuple = collections.namedtuple | 39 namedtuple = collections.namedtuple |
39 Mapping = collections.Mapping | 40 Mapping = collections.Mapping |
40 | 41 |
41 try: | 42 try: |
286 return select.select(r, w, [], timeout) | 287 return select.select(r, w, [], timeout) |
287 | 288 |
288 __all__.append('SelectSelector') | 289 __all__.append('SelectSelector') |
289 | 290 |
290 # Jython has a different implementation of .fileno() for socket objects. | 291 # Jython has a different implementation of .fileno() for socket objects. |
291 if platform.system() == 'Java': | 292 if pycompat.isjython: |
292 class _JythonSelectorMapping(object): | 293 class _JythonSelectorMapping(object): |
293 """ This is an implementation of _SelectorMapping that is built | 294 """ This is an implementation of _SelectorMapping that is built |
294 for use specifically with Jython, which does not provide a hashable | 295 for use specifically with Jython, which does not provide a hashable |
295 value from socket.socket.fileno(). """ | 296 value from socket.socket.fileno(). """ |
296 | 297 |
725 """ This function serves as a first call for DefaultSelector to | 726 """ This function serves as a first call for DefaultSelector to |
726 detect if the select module is being monkey-patched incorrectly | 727 detect if the select module is being monkey-patched incorrectly |
727 by eventlet, greenlet, and preserve proper behavior. """ | 728 by eventlet, greenlet, and preserve proper behavior. """ |
728 global _DEFAULT_SELECTOR | 729 global _DEFAULT_SELECTOR |
729 if _DEFAULT_SELECTOR is None: | 730 if _DEFAULT_SELECTOR is None: |
730 if platform.system() == 'Java': # Platform-specific: Jython | 731 if pycompat.isjython: |
731 _DEFAULT_SELECTOR = JythonSelectSelector | 732 _DEFAULT_SELECTOR = JythonSelectSelector |
732 elif _can_allocate('kqueue'): | 733 elif _can_allocate('kqueue'): |
733 _DEFAULT_SELECTOR = KqueueSelector | 734 _DEFAULT_SELECTOR = KqueueSelector |
734 elif _can_allocate('devpoll'): | 735 elif _can_allocate('devpoll'): |
735 _DEFAULT_SELECTOR = DevpollSelector | 736 _DEFAULT_SELECTOR = DevpollSelector |