tools/sublime/compile_current_file.py
def execute_command(self, command, cwd):
    """Execute the provided command and send ouput to panel.

    Because the implementation of subprocess can deadlock on windows, we use
    a Queue that we write to from another thread to avoid blocking on IO.

    Args:
      command: A list containing the command to execute and it's arguments.
    Returns:
      The exit code of the process running the command or,
       1 if we got interrupted.
      -1 if we couldn't start the process
      -2 if we couldn't poll the running process
    """
    logging.debug("Running command: %s", command)

    def EnqueueOutput(out, queue):
      """Read all the output from the given handle and insert it into the queue.

      Args:
        queue: The Queue object to write to.
      """
      while True:
        # This readline will block until there is either new input or the handle
        # is closed. Readline will only return None once the handle is close, so
        # even if the output is being produced slowly, this function won't exit
        # early.
        # The potential dealock here is acceptable because this isn't run on the
        # main thread.
        data = out.readline()
        if not data:
          break
        queue.put(data, block=True)
      out.close()

    try:
      os.chdir(cwd)
      proc = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True,
                              stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
    except OSError as e:
      logging.exception('Execution of %s raised exception: %s.', (command, e))
      return -1

    # Use a Queue to pass the text from the reading thread to this one.
    stdout_queue = Queue.Queue()
    stdout_thread = threading.Thread(target=EnqueueOutput,
                                     args=(proc.stdout, stdout_queue))
    stdout_thread.daemon = True  # Ensure this exits if the parent dies
    stdout_thread.start()

    # We use the self.interrupted flag to stop this thread.
    while not self.interrupted:
      try:
        exit_code = proc.poll()
      except OSError as e:
        logging.exception('Polling execution of %s raised exception: %s.',
                          command, e)
        return -2

      # Try to read output content from the queue
      current_content = ""
      for _ in range(2048):
        try:
          current_content += stdout_queue.get_nowait().decode('utf-8')
        except Queue.Empty:
          break
      self.update_panel_text(current_content)
      current_content = ""
      if exit_code is not None:
        while stdout_thread.isAlive() or not stdout_queue.empty():
          try:
            current_content += stdout_queue.get(
                               block=True, timeout=1).decode('utf-8')
          except Queue.Empty:
            # Queue could still potentially contain more input later.
            pass
        time_length = datetime.datetime.now() - self.start_time
        self.update_panel_text("%s\nDone!\n(%s seconds)" %
                               (current_content, time_length.seconds))
        return exit_code
      # We sleep a little to give the child process a chance to move forward
      # before we poll it again.
      time.sleep(0.1)

    # If we get here, it's because we were interrupted, kill the process.
    proc.terminate()
    return 1
Execute the provided command and send ouput to panel.

    Because the implementation of subprocess can deadlock on windows, we use
    a Queue that we write to from another thread to avoid blocking on IO.

    Args:
      command: A list containing the command to execute and it's arguments.
    Returns:
      The exit code of the process running the command or,
       1 if we got interrupted.
      -1 if we couldn't start the process
      -2 if we couldn't poll the running process
    
Execute the provided command and send ouput to panel.
Because the implementation of subprocess can deadlock on windows, we use
a Queue that we write to from another thread to avoid blocking on IO.
Execute the provided command and send ouput to panel . Because the implementation of subprocess can deadlock on windows we use a Queue that we write to from another thread to avoid blocking on IO .
def execute_command(self, command, cwd):
    logging.debug("Running command: %s", command)
    def EnqueueOutput(out, queue):
      while True:
        data = out.readline()
        if not data:
          break
        queue.put(data, block=True)
      out.close()
    try:
      os.chdir(cwd)
      proc = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True,
                              stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
    except OSError as e:
      logging.exception('Execution of %s raised exception: %s.', (command, e))
      return -1
    stdout_queue = Queue.Queue()
    stdout_thread = threading.Thread(target=EnqueueOutput,
                                     args=(proc.stdout, stdout_queue))
    stdout_thread.daemon = True  
    stdout_thread.start()
    while not self.interrupted:
      try:
        exit_code = proc.poll()
      except OSError as e:
        logging.exception('Polling execution of %s raised exception: %s.',
                          command, e)
        return -2
      current_content = ""
      for _ in range(2048):
        try:
          current_content += stdout_queue.get_nowait().decode('utf-8')
        except Queue.Empty:
          break
      self.update_panel_text(current_content)
      current_content = ""
      if exit_code is not None:
        while stdout_thread.isAlive() or not stdout_queue.empty():
          try:
            current_content += stdout_queue.get(
                               block=True, timeout=1).decode('utf-8')
          except Queue.Empty:
            pass
        time_length = datetime.datetime.now() - self.start_time
        self.update_panel_text("%s\nDone!\n(%s seconds)" %
                               (current_content, time_length.seconds))
        return exit_code
      time.sleep(0.1)
    proc.terminate()
    return 1
def execute_command ( self , command , cwd ) : logging . debug ( "Running command: %s" , command ) def EnqueueOutput ( out , queue ) : """Read all the output from the given handle and insert it into the queue.

      Args:
        queue: The Queue object to write to.
      """ while True : data = out . readline ( ) if not data : break queue . put ( data , block = True ) out . close ( ) try : os . chdir ( cwd ) proc = subprocess . Popen ( command , stdout = subprocess . PIPE , shell = True , stderr = subprocess . STDOUT , stdin = subprocess . PIPE ) except OSError as e : logging . exception ( 'Execution of %s raised exception: %s.' , ( command , e ) ) return - 1 stdout_queue = Queue . Queue ( ) stdout_thread = threading . Thread ( target = EnqueueOutput , args = ( proc . stdout , stdout_queue ) ) stdout_thread . daemon = True stdout_thread . start ( ) while not self . interrupted : try : exit_code = proc . poll ( ) except OSError as e : logging . exception ( 'Polling execution of %s raised exception: %s.' , command , e ) return - 2 current_content = "" for _ in range ( 2048 ) : try : current_content += stdout_queue . get_nowait ( ) . decode ( 'utf-8' ) except Queue . Empty : break self . update_panel_text ( current_content ) current_content = "" if exit_code is not None : while stdout_thread . isAlive ( ) or not stdout_queue . empty ( ) : try : current_content += stdout_queue . get ( block = True , timeout = 1 ) . decode ( 'utf-8' ) except Queue . Empty : pass time_length = datetime . datetime . now ( ) - self . start_time self . update_panel_text ( "%s\nDone!\n(%s seconds)" % ( current_content , time_length . seconds ) ) return exit_code time . sleep ( 0.1 ) proc . terminate ( ) return 1
Execute the provided command and send ouput to panel.
Execute the provided command and send ouput to panel .
"""Execute the provided command and send ouput to panel.

    Because the implementation of subprocess can deadlock on windows, we use
    a Queue that we write to from another thread to avoid blocking on IO.

    Args:
      command: A list containing the command to execute and it's arguments.
    Returns:
      The exit code of the process running the command or,
       1 if we got interrupted.
      -1 if we couldn't start the process
      -2 if we couldn't poll the running process
    """ """Read all the output from the given handle and insert it into the queue.

      Args:
        queue: The Queue object to write to.
      """ # This readline will block until there is either new input or the handle # is closed. Readline will only return None once the handle is close, so # even if the output is being produced slowly, this function won't exit # early. # The potential dealock here is acceptable because this isn't run on the # main thread. # Use a Queue to pass the text from the reading thread to this one. # Ensure this exits if the parent dies # We use the self.interrupted flag to stop this thread. # Try to read output content from the queue # Queue could still potentially contain more input later. # We sleep a little to give the child process a chance to move forward # before we poll it again. # If we get here, it's because we were interrupted, kill the process.
The exit code of the process running the command or,
1 if we got interrupted.
1 if we couldn't start the process
2 if we couldn't poll the running process
The exit code of the process running the command or 1 if we got interrupted . 1 if we couldn ' t start the process 2 if we couldn ' t poll the running process
self
command
A list containing the command to execute and it's arguments.
A list containing the command to execute and it ' s arguments .
cwd