Avoid using select() on Windows
Markus Gerstel
6 years ago
115 | 115 | if notify: |
116 | 116 | notify() |
117 | 117 | |
118 | self._thread = Thread(target = _thread_write_stream_to_buffer) | |
118 | def _thread_write_stream_to_buffer_windows(): | |
119 | line = True | |
120 | while line: | |
121 | line = self._stream.readline() | |
122 | if line: | |
123 | self._buffer.write(line) | |
124 | if output or callback: | |
125 | linedecode = line.decode('utf-8') | |
126 | if output: | |
127 | print(linedecode) | |
128 | if callback: | |
129 | callback(linedecode) | |
130 | self._terminated = True | |
131 | if self._debug: | |
132 | logger.debug("Stream reader terminated") | |
133 | if notify: | |
134 | notify() | |
135 | ||
136 | if os.name == "nt": | |
137 | self._thread = Thread(target = _thread_write_stream_to_buffer_windows) | |
138 | else: | |
139 | self._thread = Thread(target = _thread_write_stream_to_buffer) | |
119 | 140 | self._thread.daemon = True |
120 | 141 | self._thread.start() |
121 | 142 | |
266 | 287 | if thread_pipe_pool: |
267 | 288 | # Wait for up to 0.5 seconds or for a signal on a remaining stream, |
268 | 289 | # which could indicate that the process has terminated. |
269 | event = thread_pipe_pool[0].poll(0.5) | |
290 | try: | |
291 | event = thread_pipe_pool[0].poll(0.5) | |
292 | except IOError as e: | |
293 | # on Windows this raises "IOError: [Errno 109] The pipe has been ended" | |
294 | # which is for all intents and purposes equivalent to a True return value. | |
295 | if e.errno != 109: raise | |
296 | event = True | |
270 | 297 | if event: |
271 | 298 | # One-shot, so remove stream and watch remaining streams |
272 | 299 | thread_pipe_pool.pop(0) |