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)
| 1080 | _ready_errors = {_winapi.ERROR_BROKEN_PIPE, _winapi.ERROR_NETNAME_DELETED} |
| 1081 | |
| 1082 | def wait(object_list, timeout=None): |
| 1083 | ''' |
| 1084 | Wait till an object in object_list is ready/readable. |
| 1085 | |
| 1086 | Returns list of those objects in object_list which are ready/readable. |
| 1087 | ''' |
| 1088 | object_list = list(object_list) |
| 1089 | |
| 1090 | if not object_list: |
| 1091 | if timeout is None: |
| 1092 | while True: |
| 1093 | time.sleep(1e6) |
| 1094 | elif timeout > 0: |
| 1095 | time.sleep(timeout) |
| 1096 | return [] |
| 1097 | |
| 1098 | if timeout is None: |
| 1099 | timeout = INFINITE |
| 1100 | elif timeout < 0: |
| 1101 | timeout = 0 |
| 1102 | else: |
| 1103 | timeout = int(timeout * 1000 + 0.5) |
| 1104 | waithandle_to_obj = {} |
| 1105 | ov_list = [] |
| 1106 | ready_objects = set() |
| 1107 | ready_handles = set() |
| 1108 | |
| 1109 | try: |
| 1110 | for o in object_list: |
| 1111 | try: |
| 1112 | fileno = getattr(o, 'fileno') |
| 1113 | except AttributeError: |
| 1114 | waithandle_to_obj[o.__index__()] = o |
| 1115 | else: |
| 1116 | # start an overlapped read of length zero |
| 1117 | try: |
| 1118 | ov, err = _winapi.ReadFile(fileno(), 0, True) |
| 1119 | except OSError as e: |
| 1120 | ov, err = None, e.winerror |
| 1121 | if err not in _ready_errors: |
| 1122 | raise |
| 1123 | if err == _winapi.ERROR_IO_PENDING: |
| 1124 | ov_list.append(ov) |
| 1125 | waithandle_to_obj[ov.event] = o |
| 1126 | else: |
| 1127 | # If o.fileno() is an overlapped pipe handle and |
| 1128 | # err == 0 then there is a zero length message |
| 1129 | # in the pipe, but it HAS NOT been consumed... |
| 1130 | if ov and sys.getwindowsversion()[:2] >= (6, 2): |
| 1131 | # ... except on Windows 8 and later, where |
| 1132 | # the message HAS been consumed. |
| 1133 | try: |
| 1134 | _, err = ov.GetOverlappedResult(False) |
| 1135 | except OSError as e: |
| 1136 | err = e.winerror |
| 1137 | if not err and hasattr(o, '_got_empty_message'): |
| 1138 | o._got_empty_message = True |
| 1139 | ready_objects.add(o) |
searching dependent graphs…