diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:39 +0300 |
commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Lib/selectors.py | |
parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
download | ydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Lib/selectors.py')
-rw-r--r-- | contrib/tools/python3/src/Lib/selectors.py | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/contrib/tools/python3/src/Lib/selectors.py b/contrib/tools/python3/src/Lib/selectors.py index f32c0a25df..bb15a1cb1b 100644 --- a/contrib/tools/python3/src/Lib/selectors.py +++ b/contrib/tools/python3/src/Lib/selectors.py @@ -57,7 +57,7 @@ if sys.version_info >= (3, 5): SelectorKey.data.__doc__ = ('''Optional opaque data associated to this file object. For example, this could be used to store a per-client session ID.''') - + class _SelectorMapping(Mapping): """Mapping of file objects to selector keys.""" @@ -553,10 +553,10 @@ if hasattr(select, 'kqueue'): def select(self, timeout=None): timeout = None if timeout is None else max(timeout, 0) - # If max_ev is 0, kqueue will ignore the timeout. For consistent - # behavior with the other selector classes, we prevent that here - # (using max). See https://bugs.python.org/issue29255 - max_ev = max(len(self._fd_to_key), 1) + # If max_ev is 0, kqueue will ignore the timeout. For consistent + # behavior with the other selector classes, we prevent that here + # (using max). See https://bugs.python.org/issue29255 + max_ev = max(len(self._fd_to_key), 1) ready = [] try: kev_list = self._selector.control(None, max_ev, timeout) @@ -581,39 +581,39 @@ if hasattr(select, 'kqueue'): super().close() -def _can_use(method): - """Check if we can use the selector depending upon the - operating system. """ - # Implementation based upon https://github.com/sethmlarson/selectors2/blob/master/selectors2.py - selector = getattr(select, method, None) - if selector is None: - # select module does not implement method - return False - # check if the OS and Kernel actually support the method. Call may fail with - # OSError: [Errno 38] Function not implemented - try: - selector_obj = selector() - if method == 'poll': - # check that poll actually works - selector_obj.poll(0) - else: - # close epoll, kqueue, and devpoll fd - selector_obj.close() - return True - except OSError: - return False - - +def _can_use(method): + """Check if we can use the selector depending upon the + operating system. """ + # Implementation based upon https://github.com/sethmlarson/selectors2/blob/master/selectors2.py + selector = getattr(select, method, None) + if selector is None: + # select module does not implement method + return False + # check if the OS and Kernel actually support the method. Call may fail with + # OSError: [Errno 38] Function not implemented + try: + selector_obj = selector() + if method == 'poll': + # check that poll actually works + selector_obj.poll(0) + else: + # close epoll, kqueue, and devpoll fd + selector_obj.close() + return True + except OSError: + return False + + # Choose the best implementation, roughly: # epoll|kqueue|devpoll > poll > select. # select() also can't accept a FD > FD_SETSIZE (usually around 1024) -if _can_use('kqueue'): +if _can_use('kqueue'): DefaultSelector = KqueueSelector -elif _can_use('epoll'): +elif _can_use('epoll'): DefaultSelector = EpollSelector -elif _can_use('devpoll'): +elif _can_use('devpoll'): DefaultSelector = DevpollSelector -elif _can_use('poll'): +elif _can_use('poll'): DefaultSelector = PollSelector else: DefaultSelector = SelectSelector |