Wraps the execution of check_output in a way that
    ignores stderr when not in debug mode
331970
def stderr_output(cmd):
    """"""

    handle, gpg_stderr = stderr_handle()
    try:
        output = subprocess.check_output(cmd, stderr=gpg_stderr)  # nosec
        if handle:
            handle.close()

        return str(polite_string(output))
    except subprocess.CalledProcessError as exception:
        LOGGER.debug("GPG Command %s", ' '.join(exception.cmd))
        LOGGER.debug("GPG Output %s", exception.output)
        raise CryptoritoError('GPG Execution')
922736
def debug(msg):
    '''
    
    '''
    if DEBUG:
        sys.stderr.write("DEBUG: " + msg + "\n")
        sys.stderr.flush()
879186
def check_call_no_output(args):
    
    logger = logging.getLogger(__name__)
    logger.debug("running %s", args)
    process = subprocess.Popen(
        args,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    (res_stdout, res_stderr) = process.communicate()
    if process.returncode:
        res_stdout = res_stdout
        res_stderr = res_stderr
        print(res_stdout, end='')
        print(res_stderr, end='')
        raise ValueError('exit code from [{}] was [{}]'.format(" ".join(args), process.returncode))
1155591
def output_callback(self, out, process_status):
        
        self.final_status.append(process_status)
        self.final_output.append(out)
819029
def succ(cmd, check_stderr=True, stdout=None, stderr=None):
    '''
    
    '''
    code, out, err = run(cmd)

    # Because we're raising error, sometimes we want to process stdout/stderr after catching error
    # so we're copying these outputs if required
    if stdout is not None:
        stdout[:] = out
    if stderr is not None:
        stderr[:] = err

    if code != 0:
        for l in out:
            print(l)
    assert code == 0, 'Return: {} {}\nStderr: {}'.format(code, cmd, err)
    if check_stderr:
        assert err == [], 'Error: {} {}'.format(err, code)
    return code, out, err
264459
def shell_out_ignore_exitcode(cmd, stderr=STDOUT, cwd=None):
    """"""
    try:
        return shell_out(cmd, stderr=stderr, cwd=cwd)
    except CalledProcessError as c:
        return _clean_output(c.output)
136545
def stderr(msg, silent=False):
    
    if not silent:
        print(msg, file=sys.stderr)
697831
def _emit_error(cls, message):
        """"""
        sys.stderr.write('ERROR: {message}\n'.format(message=message))
        sys.stderr.flush()
612409
def log_hack
      read_stderr, write_stderr = IO.pipe

      fork do
        write_stderr.close

        read_stderr.each do |l|
          @log.trace "GFS: #{l.chomp.strip}"
        end

        read_stderr.close
      end

      old_stderr = STDERR.clone

      STDERR.reopen(write_stderr)
      STDERR.sync = true

      begin
        # Execute all tasks
        yield if block_given?
      ensure
        STDERR.reopen(old_stderr)
      end

      write_stderr.close
      read_stderr.close

      Process.wait
    end
420953
def _run_with_output_on_failure(self, cmd, non_blocking=False,
                                  ignore_errors=False,
                                  max_wait_sec=365 * 24 * 3600,
                                  check_interval=0.2) -> str:
    """"""

    if not self._can_run:
      assert False, "Using .run before initialization finished"

    if '\n' in cmd:
      assert False, "Don't support multi-line for run2"

    cmd = cmd.strip()
    if cmd.startswith('#'):  # ignore empty/commented out lines
      return ''
    self.run_counter += 1
    self.log("tmux> %s", cmd)

    self._cmd = cmd
    self._cmd_fn = f'{self.remote_scratch}/{self.run_counter}.cmd'
    self._status_fn = f'{self.remote_scratch}/{self.run_counter}.status'
    self._out_fn = f'{self.remote_scratch}/{self.run_counter}.out'

    cmd = util.shell_strip_comment(cmd)
    assert '&' not in cmd, f"cmd {cmd} contains &, that breaks things"

    # modify command to dump shell success status into file
    self.file_write(self._cmd_fn, cmd + '\n')

    #    modified_cmd = f'{cmd} > {out_fn} 2>&1; echo $? > {status_fn}'
    # https://stackoverflow.com/a/692407/419116
    # $cmd > >(tee -a fn) 2> >(tee -a fn >&2)

    modified_cmd = f'{cmd} > >(tee -a {self._out_fn}) 2> >(tee -a {self._out_fn} >&2); echo $? > {self._status_fn}'
    modified_cmd = shlex.quote(modified_cmd)

    start_time = time.time()
    tmux_window = self.tmux_session + ':' + str(self.tmux_window_id)
    tmux_cmd = f"tmux send-keys -t {tmux_window} {modified_cmd} Enter"
    self._run_raw(tmux_cmd, ignore_errors=ignore_errors)
    if non_blocking:
      return 0

    if not self.wait_for_file(self._status_fn, max_wait_sec=60):
      self.log(f"Retrying waiting for {self._status_fn}")
    elapsed_time = time.time() - start_time
    while not self.exists(self._status_fn) and elapsed_time < max_wait_sec:
      self.log(f"Still waiting for {cmd}")
      self.wait_for_file(self._status_fn, max_wait_sec=60)
      elapsed_time = time.time() - start_time
    contents = self.read(self._status_fn)

    # if empty wait a bit to allow for race condition
    if len(contents) == 0:
      time.sleep(check_interval)
      contents = self.read(self._status_fn)
    status = int(contents.strip())
    self.last_status = status

    if status != 0:
      extra_msg = '(ignoring error)' if ignore_errors else '(failing)'
      self.log(
        f"Start failing output {extra_msg}: \n{'*'*80}\n\n '{self.read(self._out_fn)}'")
      self.log(f"\n{'*'*80}\nEnd failing output")
      if not ignore_errors:
        raise RuntimeError(f"Command {cmd} returned status {status}")
      else:
        self.log(f"Warning: command {cmd} returned status {status}")

    return self.read(self._out_fn)
211390
async def stderr_handler(self, line):
        

        await self.queue.put(self.clean_bytes(b'[stderr] ' + line))
1015459
def debug(message, *args, **kwargs):
    
    if 'end' in kwargs:
        end = kwargs['end']
    else:
        end = '\n'

    if DEBUG: 
        if len(args) == 0:
            sys.stderr.write(message)
        else:
            sys.stderr.write(message % args)

        sys.stderr.write(end)
        sys.stderr.flush()
578241
def print_err(*args, end='\n'):
    
    print(*args, end=end, file=sys.stderr)
    sys.stderr.flush()
270615
def handle_stderr(stream)
      @err_array = []
      # synchronize access to @err_array
      @semaphore = Mutex.new
      Thread.new do
        until (line = stream.gets).nil?
          line.strip!
          @semaphore.synchronize { @err_array << line if line.size > 3 }
        end
      end
    end
1100709
def check_output(self, cmd, timeout=None, keep_rc=False, env=None):
        
        return subproc.call(cmd, timeout=timeout or self.timeout,
                keep_rc=keep_rc, env=env)
797750
def error(*args):
    """"""
    if sys.stdin.isatty():
        print('ERROR:', *args, file=sys.stderr)
    else:
        notify_error(*args)
28958
def get_simple_output(self, stderr=STDOUT):
        
        args = shlex.split(self.cmd)
        proc = Popen(args, stdout=PIPE, stderr=stderr)
        return proc.communicate()[0].decode("utf8")