Check if we can use the selector depending upon the operating system.
(method)
| 586 | |
| 587 | |
| 588 | def _can_use(method): |
| 589 | """Check if we can use the selector depending upon the |
| 590 | operating system. """ |
| 591 | # Implementation based upon https://github.com/sethmlarson/selectors2/blob/master/selectors2.py |
| 592 | selector = getattr(select, method, None) |
| 593 | if selector is None: |
| 594 | # select module does not implement method |
| 595 | return False |
| 596 | # check if the OS and Kernel actually support the method. Call may fail with |
| 597 | # OSError: [Errno 38] Function not implemented |
| 598 | try: |
| 599 | selector_obj = selector() |
| 600 | if method == 'poll': |
| 601 | # check that poll actually works |
| 602 | selector_obj.poll(0) |
| 603 | else: |
| 604 | # close epoll, kqueue, and devpoll fd |
| 605 | selector_obj.close() |
| 606 | return True |
| 607 | except OSError: |
| 608 | return False |
| 609 | |
| 610 | |
| 611 | # Choose the best implementation, roughly: |
no test coverage detected