Check if we can use the selector depending upon the operating system.
(method)
| 566 | |
| 567 | |
| 568 | def _can_use(method): |
| 569 | """Check if we can use the selector depending upon the |
| 570 | operating system. """ |
| 571 | # Implementation based upon https://github.com/sethmlarson/selectors2/blob/master/selectors2.py |
| 572 | selector = getattr(select, method, None) |
| 573 | if selector is None: |
| 574 | # select module does not implement method |
| 575 | return False |
| 576 | # check if the OS and Kernel actually support the method. Call may fail with |
| 577 | # OSError: [Errno 38] Function not implemented |
| 578 | try: |
| 579 | selector_obj = selector() |
| 580 | if method == 'poll': |
| 581 | # check that poll actually works |
| 582 | selector_obj.poll(0) |
| 583 | else: |
| 584 | # close epoll, kqueue, and devpoll fd |
| 585 | selector_obj.close() |
| 586 | return True |
| 587 | except OSError: |
| 588 | return False |
| 589 | |
| 590 | |
| 591 | # Choose the best implementation, roughly: |
no test coverage detected
searching dependent graphs…