237 | | pollster.register(infile.fileno(), select.POLLIN) |
238 | | pollster.register(subprocess.fromchild.fileno(), select.POLLIN) |
239 | | pollster.register(subprocess.childerr.fileno(), select.POLLIN) |
240 | | pollster.register(subprocess.tochild.fileno(), select.POLLOUT) |
241 | | inputdata = "" |
| 241 | infno = infile.fileno() |
| 242 | stdoutfno = sys.stdout.fileno() |
| 243 | stderrfno = sys.stderr.fileno() |
| 244 | fromcfno = subprocess.fromchild.fileno() |
| 245 | tocfno = subprocess.tochild.fileno() |
| 246 | cerrfno = subprocess.childerr.fileno() |
| 247 | pollster.register(infno, select.POLLIN | select.POLLPRI) |
| 248 | pollster.register(fromcfno, select.POLLIN | select.POLLPRI) |
| 249 | pollster.register(cerrfno, select.POLLIN | select.POLLPRI) |
| 250 | pollster.register(stdoutfno, select.POLLOUT) |
| 251 | pollster.register(stderrfno, select.POLLOUT) |
| 252 | pollster.register(tocfno, select.POLLOUT) |
| 253 | indata = "" |
| 254 | outdata = "" |
| 255 | errdata = "" |
244 | | availablestreams = pollster.poll() |
245 | | for (stream, mask) in availablestreams : |
246 | | if mask & select.POLLHUP : |
247 | | if stream == infile.fileno() : |
248 | | end = 1 |
249 | | if mask & select.POLLOUT : |
250 | | if stream == subprocess.tochild.fileno() : |
251 | | if inputdata : |
252 | | os.write(stream, inputdata) |
253 | | inputdata = "" |
254 | | if mask & select.POLLIN : |
255 | | data = os.read(stream, 256 * 1024) |
256 | | if stream == infile.fileno() : |
257 | | inputdata += data |
258 | | elif stream == subprocess.fromchild.fileno() : |
259 | | sys.stdout.write(data) |
260 | | elif stream == subprocess.childerr.fileno() : |
261 | | sys.stderr.write(data) |
262 | | if inputdata : |
| 258 | availablefds = pollster.poll(500) |
| 259 | if not availablefds : |
| 260 | end = 1 |
| 261 | else : |
| 262 | for (fd, mask) in availablefds : |
| 263 | thebackend.logdebug("Stream: %02i Mask: %02x" % (fd, mask)) |
| 264 | if mask & select.POLLHUP : |
| 265 | if fd == infno : |
| 266 | end = 1 # this happens with real stdin |
| 267 | if mask & select.POLLOUT : |
| 268 | if fd == tocfno : |
| 269 | if indata : |
| 270 | os.write(fd, indata) |
| 271 | indata = "" |
| 272 | elif fd == stdoutfno : |
| 273 | if outdata : |
| 274 | os.write(fd, outdata) |
| 275 | outdata = "" |
| 276 | elif fd == stderrfno : |
| 277 | if errdata : |
| 278 | os.write(fd, errdata) |
| 279 | errdata = "" |
| 280 | if (mask & select.POLLIN) or (mask & select.POLLPRI) : |
| 281 | data = os.read(fd, 256 * 1024) |
| 282 | if fd == infno : |
| 283 | indata += data |
| 284 | if not data : |
| 285 | end = 1 # this happens with real files |
| 286 | elif fd == fromcfno : |
| 287 | outdata += data |
| 288 | elif fd == cerrfno : |
| 289 | errdata += data |
| 290 | if indata : |