当前位置: 首页>>代码示例>>Python>>正文


Python subprocess.Popen方法代码示例

本文整理汇总了Python中gevent.subprocess.Popen方法的典型用法代码示例。如果您正苦于以下问题:Python subprocess.Popen方法的具体用法?Python subprocess.Popen怎么用?Python subprocess.Popen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gevent.subprocess的用法示例。


在下文中一共展示了subprocess.Popen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _reap_workers

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def _reap_workers(workers, to_close, debug_log):
    """Collects the IO workers created with _mk_workers.

    After killing the workers, also closes the subprocess's open PIPE handles.

    See _safe_close for caveats around closing handles on windows.

    Args:
      * workers (List[Greenlet]) - The IO workers to kill.
      * to_close (List[...]) - (see _mk_workers for definition). The handles to
        close. These originate from the `Popen.std{out,err}` handles when the
        recipe engine had to use PIPEs.
      * debug_log (..stream.StreamEngine.Stream)

    Should not raise an exception.
    """
    debug_log.write_line('reaping IO workers...')
    for worker in workers:
      worker.kill()
    gevent.wait(workers)
    debug_log.write_line('  done')
    for handle_name, handle in to_close:
      _safe_close(debug_log, handle_name, handle) 
开发者ID:luci,项目名称:recipes-py,代码行数:25,代码来源:subproc.py

示例2: _htmlize

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def _htmlize(ansi_output, title, parsed_query):
    """Return HTML representation of `ansi_output`.
    Use `title` as the title of the page.
    Format page according to query parameters from `parsed_query`."""

    cmd = ["bash", ANSI2HTML, "--palette=solarized"]
    if not parsed_query.get('inverted_colors'):
        cmd += ["--bg=dark"]

    proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
    stdout, stderr = proc.communicate(ansi_output.encode("utf-8"))
    stdout = stdout.decode("utf-8")
    stderr = stderr.decode("utf-8")
    if proc.returncode != 0:
        error(stdout + stderr)

    if parsed_query.get('inverted_colors'):
        stdout = stdout.replace(
            '<body class="">', '<body class="" style="background:white;color:#777777">')

    title = "<title>%s</title>" % title
    opengraph = _get_opengraph(parsed_query)
    stdout = re.sub("<head>", "<head>" + title + opengraph, stdout)
    return stdout 
开发者ID:chubin,项目名称:wttr.in,代码行数:26,代码来源:wttr.py

示例3: kill_all

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def kill_all(name):
    kill_all_popen = subprocess.Popen(["killall", "-9", name],
                                       stdin=DEVNULL,
                                       stdout=DEVNULL,
                                       stderr=DEVNULL,
                                       close_fds=True,
                                       shell=False)

    try:
        ret = kill_all_popen.wait(DEFAULT_STOP_WAIT_TIMEOUT)
    except subprocess.TimeoutExpired:
        ret = None

    if ret is None:
        kill_all_popen.kill()
        kill_all_popen.wait() 
开发者ID:OpenSight,项目名称:janus-cloud,代码行数:18,代码来源:process_mngr.py

示例4: qrencode_wrapper

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def qrencode_wrapper(query_string="", request_options=None, html=False):

    if query_string == "":
        query_string = ":firstpage"
    
    if query_string in INTERNAL_TOPICS:
        answer = get_internal(query_string)
    else:
        answer = query_string + "\n"
        cmd = ["qrencode", "-t", "UTF8", "-o", "-"]
        p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
        answer = p.communicate(answer.encode('utf-8'))[0]

    if html:
        return html_wrapper(answer), True
    else:
        return answer, True 
开发者ID:chubin,项目名称:qrenco.de,代码行数:19,代码来源:qrencode_wrapper.py

示例5: html_wrapper

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def html_wrapper(data):
    p = Popen([ "bash", ANSI2HTML, "--palette=xterm", "--bg=dark" ],  stdin=PIPE, stdout=PIPE, stderr=PIPE)
    data = data.encode('utf-8')
    stdout, stderr = p.communicate(data)
    if p.returncode != 0:
        error(stdout + stderr)
    return stdout.decode('utf-8') 
开发者ID:chubin,项目名称:rate.sx,代码行数:9,代码来源:cmd_wrapper.py

示例6: _git

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def _git(self, cmd, stdin=None):
    """Executes a git command and returns the standard output."""
    p = subprocess.Popen(['git'] + cmd, cwd=self._repo, stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE)
    stdout, _ = p.communicate(stdin)
    if p.returncode != 0:
      raise subprocess.CalledProcessError(p.returncode, ['git'] + cmd, None)
    return stdout.strip().splitlines() 
开发者ID:luci,项目名称:recipes-py,代码行数:10,代码来源:gitattr_checker.py

示例7: run_simulation_test

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def run_simulation_test(repo, *additional_args):
  """Runs the recipe simulation test for given repo.

  Returns a tuple of exit code and output.
  """
  proc = subprocess.Popen([
    VPYTHON, os.path.join(repo.recipes_root_path, 'recipes.py'), 'test',
  ] + list(additional_args), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  output, _ = proc.communicate()
  retcode = proc.returncode
  return retcode, output 
开发者ID:luci,项目名称:recipes-py,代码行数:13,代码来源:cmd.py

示例8: __init__

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def __init__(self, recipe_deps, description_queue, outcome_queue, is_train,
               cov_file, cover_module_imports):
    super(RunnerThread, self).__init__()

    self.cov_file = cov_file

    cmd = [
      sys.executable, '-u', sys.argv[0],
      '--package', os.path.join(
          recipe_deps.main_repo.path, RECIPES_CFG_LOCATION_REL),
      '--proto-override', os.path.dirname(PB.__path__[0]),
    ]
    # Carry through all repos explicitly via overrides
    for repo_name, repo in recipe_deps.repos.iteritems():
      if repo_name == recipe_deps.main_repo.name:
        continue
      cmd.extend(['-O', '%s=%s' % (repo_name, repo.path)])

    cmd.extend(['test', '_runner'])
    if is_train:
      cmd.append('--train')
    if cov_file:
      cmd.extend(['--cov-file', cov_file])
      if cover_module_imports:
        cmd.append('--cover-module-imports')

    self._runner_proc = subprocess.Popen(
        cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    self._description_queue = description_queue
    self._outcome_queue = outcome_queue 
开发者ID:luci,项目名称:recipes-py,代码行数:32,代码来源:runner.py

示例9: _compile_protos

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def _compile_protos(proto_files, proto_tree, protoc, argfile, dest):
  """Runs protoc over the collected protos, renames them and rewrites their
  imports to make them import from `PB`.

  Args:
    * proto_files (List[Tuple[src_abspath: str, dest_relpath: str]])
    * proto_tree (str): Path to the directory with all the collected .proto
      files.
    * protoc (str): Path to the protoc binary to use.
    * argfile (str): Path to a protoc argfile containing a relative path to
      every .proto file in proto_tree on its own line.
    * dest (str): Path to the destination where the compiled protos should go.
  """
  protoc_proc = subprocess.Popen(
      [protoc, '--python_out', dest, '@'+argfile],
      cwd=proto_tree, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  output, _ = protoc_proc.communicate()
  os.remove(argfile)


  if protoc_proc.returncode != 0:
    replacer = _rel_to_abs_replacer(proto_files)
    print >> sys.stderr, "Error while compiling protobufs. Output:\n"
    sys.stderr.write(replacer(output))
    sys.exit(1)

  rewrite_errors = []
  for base, _, fnames in OS_WALK(dest):
    for name in fnames:
      err = _rewrite_and_rename(dest, os.path.join(base, name))
      if err:
        rewrite_errors.append(err)
    with open(os.path.join(base, '__init__.py'), 'wb'):
      pass

  if rewrite_errors:
    print >> sys.stderr, "Error while rewriting generated protos. Output:\n"
    replacer = _rel_to_abs_replacer(proto_files)
    for error in rewrite_errors:
      print >> sys.stderr, replacer(error)
    sys.exit(1) 
开发者ID:luci,项目名称:recipes-py,代码行数:43,代码来源:proto_support.py

示例10: _mk_workers

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def _mk_workers(step, proc, pipes):
    """Makes greenlets to shuttle lines from the process's PIPE'd std{out,err}
    handles to the recipe Step's std{out,err} handles.

    NOTE: This applies to @@@annotator@@@ runs when allow_subannotations=False;
    Step.std{out,err} will be Stream objects which don't implement `fileno()`,
    but add an '!' in front of all lines starting with '@@@'. In build.proto
    mode this code path should NOT be active at all; Placeholders will be
    redirected directly to files on disk and non-placeholders will go straight
    to butler (i.e. regular file handles).

    Args:

      * step (..step_runner.Step) - The Step object describing what we're
        supposed to run.
      * proc (subprocess.Popen) - The running subprocess.
      * pipes (Set[str]) - A subset of {'stdout', 'stderr'} to make worker
        greenlets for.

    Returns Tuple[
      workers: List[Greenlet],
      to_close: List[Tuple[
        handle_name: str,
        proc_handle: fileobj,
      ]]
    ]. Both returned values are expected to be passed directly to
    `_reap_workers` without inspection or alteration.
    """
    workers = []
    to_close = []
    for handle_name in pipes:
      proc_handle = getattr(proc, handle_name)
      to_close.append((handle_name, proc_handle))
      workers.append(gevent.spawn(
          _copy_lines, proc_handle, getattr(step, handle_name),
      ))
    return workers, to_close 
开发者ID:luci,项目名称:recipes-py,代码行数:39,代码来源:subproc.py

示例11: get_moon

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def get_moon(parsed_query):

    location = parsed_query['orig_location']
    html = parsed_query['html_output']
    lang = parsed_query['lang']

    date = None
    if '@' in location:
        date = location[location.index('@')+1:]
        location = location[:location.index('@')]

    cmd = [globals.PYPHOON]
    if lang:
        cmd += ["-l", lang]

    if date:
        try:
            dateutil.parser.parse(date)
        except Exception as e:
            print("ERROR: %s" % e)
        else:
            cmd += [date]

    p = Popen(cmd, stdout=PIPE, stderr=PIPE)
    stdout = p.communicate()[0]
    stdout = stdout.decode("utf-8")

    if parsed_query.get('no-terminal', False):
        stdout = globals.remove_ansi(stdout)

    if html:
        p = Popen(
            ["bash", globals.ANSI2HTML, "--palette=solarized", "--bg=dark"],
            stdin=PIPE, stdout=PIPE, stderr=PIPE)
        stdout, stderr = p.communicate(stdout.encode("utf-8"))
        stdout = stdout.decode("utf-8")
        stderr = stderr.decode("utf-8")
        if p.returncode != 0:
            globals.error(stdout + stderr)

    return stdout 
开发者ID:chubin,项目名称:wttr.in,代码行数:43,代码来源:moon.py

示例12: _wego_wrapper

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def _wego_wrapper(location, parsed_query):

    lang = parsed_query['lang']
    location_name = parsed_query['override_location_name']

    cmd = [WEGO, '--city=%s' % location]

    if parsed_query.get('inverted_colors'):
        cmd += ['-inverse']

    if parsed_query.get('use_ms_for_wind'):
        cmd += ['-wind_in_ms']

    if parsed_query.get('narrow'):
        cmd += ['-narrow']

    if lang and lang in SUPPORTED_LANGS:
        cmd += ['-lang=%s'%lang]

    if parsed_query.get('use_imperial', False):
        cmd += ['-imperial']

    if location_name:
        cmd += ['-location_name', location_name]

    proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
    stdout, stderr = proc.communicate()
    stdout = stdout.decode("utf-8")
    stderr = stderr.decode("utf-8")

    return stdout, stderr, proc.returncode 
开发者ID:chubin,项目名称:wttr.in,代码行数:33,代码来源:wttr.py

示例13: _auction_fucn

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def _auction_fucn(self, args):
        process = None
        try:
            process = Popen(args)
            self.processes[process.pid] = process
            rc = process.wait()
            if rc == 0:
                self.logger.info(
                    "Finished {}".format(args[2]),
                    extra={
                        'MESSAGE_ID': 'CHRONOGRAPH_WORKER_COMPLETE_SUCCESSFUL'
                    }
                )
            else:
                self.logger.error(
                    "Exit with error {}".format(args[2]),
                    extra={
                        'MESSAGE_ID': 'CHRONOGRAPH_WORKER_COMPLETE_EXCEPTION'
                    }
                )
        except Exception as error:
            self.logger.critical(
                "Exit with error {} params: {} error: {}".format(
                    args[2], repr(args), repr(error)),
                extra={'MESSAGE_ID': 'CHRONOGRAPH_WORKER_COMPLETE_EXCEPTION'})
        if process:
            del self.processes[process.pid] 
开发者ID:openprocurement,项目名称:openprocurement.auction,代码行数:29,代码来源:chronograph.py

示例14: _launch_process

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def _launch_process(self):

        self._popen = subprocess.Popen(self.args,
                                       stdin=DEVNULL,
                                       stdout=DEVNULL,
                                       stderr=DEVNULL,
                                       close_fds=True,
                                       shell=False)
        log.debug("lanch new process %s, pid:%d" % (self.args, self._popen.pid))
        self._has_aged = False
        self._proc_start_time = time.time()
        self._on_process_status_change() 
开发者ID:OpenSight,项目名称:janus-cloud,代码行数:14,代码来源:process_mngr.py

示例15: _get_page

# 需要导入模块: from gevent import subprocess [as 别名]
# 或者: from gevent.subprocess import Popen [as 别名]
def _get_page(self, topic, request_options=None):
        cmd = self._get_command(topic, request_options=request_options)
        if cmd:
            try:
                proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
                answer = proc.communicate()[0].decode('utf-8', 'ignore')
            except OSError:
                return "ERROR of the \"%s\" adapter: please create an issue" % self._adapter_name
            return answer
        return "" 
开发者ID:chubin,项目名称:cheat.sh,代码行数:12,代码来源:cmd.py


注:本文中的gevent.subprocess.Popen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。