Wait for a node to finish, and print its output.
( self, node )
| 441 | error( '*** Unknown command: %s\n' % line ) |
| 442 | |
| 443 | def waitForNode( self, node ): |
| 444 | "Wait for a node to finish, and print its output." |
| 445 | # Pollers |
| 446 | nodePoller = poll() |
| 447 | nodePoller.register( node.stdout ) |
| 448 | bothPoller = poll() |
| 449 | bothPoller.register( self.stdin, POLLIN ) |
| 450 | bothPoller.register( node.stdout, POLLIN ) |
| 451 | if self.isatty(): |
| 452 | # Buffer by character, so that interactive |
| 453 | # commands sort of work |
| 454 | quietRun( 'stty -icanon min 1' ) |
| 455 | while True: |
| 456 | try: |
| 457 | bothPoller.poll() |
| 458 | # XXX BL: this doesn't quite do what we want. |
| 459 | # pylint: disable=condition-evals-to-constant |
| 460 | if False and self.inputFile: |
| 461 | key = self.inputFile.read( 1 ) |
| 462 | if key != '': |
| 463 | node.write( key ) |
| 464 | else: |
| 465 | self.inputFile = None |
| 466 | # pylint: enable=condition-evals-to-constant |
| 467 | if isReadable( self.inPoller ): |
| 468 | key = self.stdin.read( 1 ) |
| 469 | node.write( key ) |
| 470 | if isReadable( nodePoller ): |
| 471 | data = node.monitor() |
| 472 | output( data ) |
| 473 | if not node.waiting: |
| 474 | break |
| 475 | except KeyboardInterrupt: |
| 476 | # There is an at least one race condition here, since |
| 477 | # it's possible to interrupt ourselves after we've |
| 478 | # read data but before it has been printed. |
| 479 | node.sendInt() |
| 480 | except select.error as e: |
| 481 | # pylint: disable=unpacking-non-sequence |
| 482 | # pylint: disable=unbalanced-tuple-unpacking |
| 483 | errno_, errmsg = e.args |
| 484 | if errno_ != errno.EINTR: |
| 485 | error( "select.error: %s, %s" % (errno_, errmsg) ) |
| 486 | node.sendInt() |
| 487 | |
| 488 | def precmd( self, line ): |
| 489 | "allow for comments in the cli" |