Wait till an object in object_list is ready/readable. Returns list of those objects in object_list which are ready/readable.
(object_list, timeout=None)
| 1042 | _ready_errors = {_winapi.ERROR_BROKEN_PIPE, _winapi.ERROR_NETNAME_DELETED} |
| 1043 | |
| 1044 | def wait(object_list, timeout=None): |
| 1045 | ''' |
| 1046 | Wait till an object in object_list is ready/readable. |
| 1047 | |
| 1048 | Returns list of those objects in object_list which are ready/readable. |
| 1049 | ''' |
| 1050 | if timeout is None: |
| 1051 | timeout = INFINITE |
| 1052 | elif timeout < 0: |
| 1053 | timeout = 0 |
| 1054 | else: |
| 1055 | timeout = int(timeout * 1000 + 0.5) |
| 1056 | |
| 1057 | object_list = list(object_list) |
| 1058 | waithandle_to_obj = {} |
| 1059 | ov_list = [] |
| 1060 | ready_objects = set() |
| 1061 | ready_handles = set() |
| 1062 | |
| 1063 | try: |
| 1064 | for o in object_list: |
| 1065 | try: |
| 1066 | fileno = getattr(o, 'fileno') |
| 1067 | except AttributeError: |
| 1068 | waithandle_to_obj[o.__index__()] = o |
| 1069 | else: |
| 1070 | # start an overlapped read of length zero |
| 1071 | try: |
| 1072 | ov, err = _winapi.ReadFile(fileno(), 0, True) |
| 1073 | except OSError as e: |
| 1074 | ov, err = None, e.winerror |
| 1075 | if err not in _ready_errors: |
| 1076 | raise |
| 1077 | if err == _winapi.ERROR_IO_PENDING: |
| 1078 | ov_list.append(ov) |
| 1079 | waithandle_to_obj[ov.event] = o |
| 1080 | else: |
| 1081 | # If o.fileno() is an overlapped pipe handle and |
| 1082 | # err == 0 then there is a zero length message |
| 1083 | # in the pipe, but it HAS NOT been consumed... |
| 1084 | if ov and sys.getwindowsversion()[:2] >= (6, 2): |
| 1085 | # ... except on Windows 8 and later, where |
| 1086 | # the message HAS been consumed. |
| 1087 | try: |
| 1088 | _, err = ov.GetOverlappedResult(False) |
| 1089 | except OSError as e: |
| 1090 | err = e.winerror |
| 1091 | if not err and hasattr(o, '_got_empty_message'): |
| 1092 | o._got_empty_message = True |
| 1093 | ready_objects.add(o) |
| 1094 | timeout = 0 |
| 1095 | |
| 1096 | ready_handles = _exhaustive_wait(waithandle_to_obj.keys(), timeout) |
| 1097 | finally: |
| 1098 | # request that overlapped reads stop |
| 1099 | for ov in ov_list: |
| 1100 | ov.cancel() |
| 1101 |