def input_thread(log, stdin, is_alive, quit, close_before_term):
 done = False
 closed = False
 alive = True
 writers = [stdin]
 while (writers and alive):
  (_, to_write, _) = select.select([], writers, [], 1)
  if to_write:
   log.debug('%r ready for more input', stdin)
   done = stdin.write()
   if done:
    writers = []
    if close_before_term:
     stdin.close()
     closed = True
  (alive, _) = is_alive()
 while alive:
  quit.wait(1)
  (alive, _) = is_alive()
 if (not closed):
  stdin.close()

def input_thread ( log , stdin , is_alive , quit , close_before_term ) : done = False closed = False alive = True writers = [ stdin ] while ( writers and alive ) : ( _ , to_write , _ ) = select . select ( [ ] , writers , [ ] , 1 ) if to_write : log . debug ( '%r ready for more input' , stdin ) done = stdin . write ( ) if done : writers = [ ] if close_before_term : stdin . close ( ) closed = True ( alive , _ ) = is_alive ( ) while alive : quit . wait ( 1 ) ( alive , _ ) = is_alive ( ) if ( not closed ) : stdin . close ( )
this is run in a separate thread .