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


Python process.Subprocess类代码示例

本文整理汇总了Python中tornado.process.Subprocess的典型用法代码示例。如果您正苦于以下问题:Python Subprocess类的具体用法?Python Subprocess怎么用?Python Subprocess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: EggHandler

class EggHandler(BaseHandler):

    def _handle_stdout(self, stdout):
        deps = {}
        result = REGEX.findall(stdout)
        client = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
        for dep in result:
            egg_name = dep[0]
            latest_version = client.package_releases(egg_name)[0]
            deps[egg_name] = string_version_compare(dep[1], latest_version)
            deps[egg_name]['current_version'] = dep[1]
            deps[egg_name]['latest_version'] = latest_version

        self.render('result.html', package_name=self.git_url.split('/')[-1], dependencies=deps)

    def _handle_pip_result(self, setup_py):
        self.sbp.stdout.read_until_close(self._handle_stdout)

    @tornado.web.asynchronous
    def post(self):
        self.git_url = self.get_argument('git_url')
        pip = self.find_pip()
        self.sbp = Subprocess([pip, 'install',  'git+%s' % self.git_url, '--no-install'],
                              io_loop=self.application.main_loop,
                              stdout=Subprocess.STREAM,
                              stderr=Subprocess.STREAM)

        self.sbp.set_exit_callback(self._handle_pip_result)

    @tornado.web.asynchronous
    def get(self):
        self.render('index.html')

    def find_pip(self):
        return os.path.sep.join(os.path.split(sys.executable)[:-1] + ('pip',))
开发者ID:guilhermef,项目名称:robotnik,代码行数:35,代码来源:egg.py

示例2: test_wait_for_exit_raise

 def test_wait_for_exit_raise(self):
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, "-c", "import sys; sys.exit(1)"])
     with self.assertRaises(subprocess.CalledProcessError) as cm:
         yield subproc.wait_for_exit()
     self.assertEqual(cm.exception.returncode, 1)
开发者ID:bdarnell,项目名称:tornado,代码行数:7,代码来源:process_test.py

示例3: load_sync

def load_sync(context, url, callback):
    # Disable storage of original. These lines are useful if
    # you want your Thumbor instance to store all originals persistently
    # except video frames.
    #
    # from thumbor.storages.no_storage import Storage as NoStorage
    # context.modules.storage = NoStorage(context)

    unquoted_url = unquote(url)

    command = BaseWikimediaEngine.wrap_command([
        context.config.FFPROBE_PATH,
        '-v',
        'error',
        '-show_entries',
        'format=duration',
        '-of',
        'default=noprint_wrappers=1:nokey=1',
        '%s%s' % (uri_scheme, unquoted_url)
    ], context)

    logger.debug('Command: %r' % command)

    process = Subprocess(command, stdout=Subprocess.STREAM)
    process.set_exit_callback(
        partial(
            _parse_time_status,
            context,
            unquoted_url,
            callback,
            process
        )
    )
开发者ID:wikimedia,项目名称:thumbor-video-loader,代码行数:33,代码来源:__init__.py

示例4: test_sigchild_future

 def test_sigchild_future(self):
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, "-c", "pass"])
     ret = yield subproc.wait_for_exit()
     self.assertEqual(ret, 0)
     self.assertEqual(subproc.returncode, ret)
开发者ID:bdarnell,项目名称:tornado,代码行数:7,代码来源:process_test.py

示例5: test_sigchild_signal

 def test_sigchild_signal(self):
     skip_if_twisted()
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, '-c',
                           'import time; time.sleep(30)'],
                          stdout=Subprocess.STREAM)
     self.addCleanup(subproc.stdout.close)
     subproc.set_exit_callback(self.stop)
     os.kill(subproc.pid, signal.SIGTERM)
     try:
         ret = self.wait(timeout=1.0)
     except AssertionError:
         # We failed to get the termination signal. This test is
         # occasionally flaky on pypy, so try to get a little more
         # information: did the process close its stdout
         # (indicating that the problem is in the parent process's
         # signal handling) or did the child process somehow fail
         # to terminate?
         subproc.stdout.read_until_close(callback=self.stop)
         try:
             self.wait(timeout=1.0)
         except AssertionError:
             raise AssertionError("subprocess failed to terminate")
         else:
             raise AssertionError("subprocess closed stdout but failed to "
                                  "get termination signal")
     self.assertEqual(subproc.returncode, ret)
     self.assertEqual(ret, -signal.SIGTERM)
开发者ID:conn4575,项目名称:tornado,代码行数:29,代码来源:process_test.py

示例6: send_to_ruby

    async def send_to_ruby(self, request_json):
        env = {
            "PCSD_DEBUG": "true" if self.__debug else "false"
        }
        if self.__gem_home is not None:
            env["GEM_HOME"] = self.__gem_home

        if self.__no_proxy is not None:
            env["NO_PROXY"] = self.__no_proxy
        if self.__https_proxy is not None:
            env["HTTPS_PROXY"] = self.__https_proxy

        pcsd_ruby = Subprocess(
            [
                self.__ruby_executable, "-I",
                self.__pcsd_dir,
                self.__pcsd_cmdline_entry
            ],
            stdin=Subprocess.STREAM,
            stdout=Subprocess.STREAM,
            stderr=Subprocess.STREAM,
            env=env
        )
        await Task(pcsd_ruby.stdin.write, str.encode(request_json))
        pcsd_ruby.stdin.close()
        return await multi([
            Task(pcsd_ruby.stdout.read_until_close),
            Task(pcsd_ruby.stderr.read_until_close),
            pcsd_ruby.wait_for_exit(raise_error=False),
        ])
开发者ID:tomjelinek,项目名称:pcs,代码行数:30,代码来源:ruby_pcsd.py

示例7: test_h2spec

 def test_h2spec(self):
     h2spec_cmd = [self.h2spec_path, "-p",
                   str(self.get_http_port())]
     for section in options.h2spec_section:
         h2spec_cmd.extend(["-s", section])
     h2spec_proc = Subprocess(h2spec_cmd)
     yield h2spec_proc.wait_for_exit()
开发者ID:bdarnell,项目名称:tornado_http2,代码行数:7,代码来源:h2spec_test.py

示例8: test_wait_for_exit_raise_disabled

 def test_wait_for_exit_raise_disabled(self):
     skip_if_twisted()
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, '-c', 'import sys; sys.exit(1)'])
     ret = yield subproc.wait_for_exit(raise_error=False)
     self.assertEqual(ret, 1)
开发者ID:conn4575,项目名称:tornado,代码行数:7,代码来源:process_test.py

示例9: run_proc

def run_proc(port, cmd, stdout_file, stderr_file, directory):
    run_cmd = cmd.format(numproc=port)

    if directory.startswith('.'):
        directory = os.path.realpath(directory)
        print "Directory", directory

    if not os.path.exists(directory):
        raise Exception('working directory doesnt exist')

    proc = Subprocess(
        shlex.split(run_cmd),
        stdout=Subprocess.STREAM,
        stderr=Subprocess.STREAM,
        cwd=directory
    )
    proc.set_exit_callback(exit_callback)

    std_out_log_file_name = get_out_file_name(directory, stdout_file.format(numproc=port))
    std_err_log_file_name = get_out_file_name(directory, stderr_file.format(numproc=port))
    stdout_fhandler = open(std_out_log_file_name, 'a')
    stderr_fhandler = open(std_err_log_file_name, 'a')
    out_fn = partial(_out, filehandler=stdout_fhandler, head="%s: " % port)
    err_fn = partial(_out, filehandler=stderr_fhandler, head="%s: " % port)

    proc.stdout.read_until_close(exit_callback, streaming_callback=out_fn)
    proc.stderr.read_until_close(exit_callback, streaming_callback=err_fn)

    return proc
开发者ID:Hipo,项目名称:rolld,代码行数:29,代码来源:manager.py

示例10: call_process

    def call_process(self, cmd, stream, address, io_loop=None): 
        """ Calls process 

        cmd: command in a list e.g ['ls', '-la']
        stdout_callback: callback to run on stdout


        TODO: add some way of calling proc.kill() if the stream is closed
        """

        stdout_stream = Subprocess.STREAM 
        stderr_stream = Subprocess.STREAM 
        proc = Subprocess(cmd, stdout=stdout_stream, stderr=stderr_stream)
        call_back = partial(self.on_exit, address)
        proc.set_exit_callback(call_back)

        pipe_stream = PipeIOStream(proc.stdout.fileno())

        try:
            while True:
                str_ = yield pipe_stream.read_bytes(102400, partial=True)
                yield stream.write(str_)
        except StreamClosedError:
            pass
        print("end address: {}".format(address))
开发者ID:tockards,项目名称:subprocess-tornado-server,代码行数:25,代码来源:subprocess_server.py

示例11: __init__

class GeneralSubprocess:
    def __init__(self, id, cmd):
        self.pipe = None
        self.id = id
        self.cmd = cmd
        self.start = None
        self.end = None

    @coroutine
    def run_process(self):
        self.pipe = Subprocess(shlex.split(self.cmd),
                               stdout=Subprocess.STREAM,
                               stderr=Subprocess.STREAM)
        self.start = time.time()
        (out, err) = (yield [Task(self.pipe.stdout.read_until_close),
                             Task(self.pipe.stderr.read_until_close)])
        return (out, err)

    def stat(self):
        self.pipe.poll()
        if self.pipe.returncode is not None:
            self.end = time.time()
            print('Done time : %f', self.end - self.start)
        else:
            print('Not done yet')
开发者ID:ntk148v,项目名称:tornado_wrapper,代码行数:25,代码来源:general_subprocess.py

示例12: start

def start(op,*args,**kw):
    if anonymity:
        args = ('--anonymity',str(anonymity))+args
    done = gen.Future()
    note.cyan('gnunet-'+op+' '+' '.join(args))
    action = Subprocess(('gnunet-'+op,)+args,**kw)
    action.set_exit_callback(done.set_result)
    return action, done
开发者ID:cyisfor,项目名称:gnunet-webserver,代码行数:8,代码来源:gnunet.py

示例13: test_sigchild_future

 def test_sigchild_future(self):
     skip_if_twisted()
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, '-c', 'pass'])
     ret = yield subproc.wait_for_exit()
     self.assertEqual(ret, 0)
     self.assertEqual(subproc.returncode, ret)
开发者ID:conn4575,项目名称:tornado,代码行数:8,代码来源:process_test.py

示例14: test_sigchild

 def test_sigchild(self):
     Subprocess.initialize()
     self.addCleanup(Subprocess.uninitialize)
     subproc = Subprocess([sys.executable, "-c", "pass"])
     subproc.set_exit_callback(self.stop)
     ret = self.wait()
     self.assertEqual(ret, 0)
     self.assertEqual(subproc.returncode, ret)
开发者ID:bdarnell,项目名称:tornado,代码行数:8,代码来源:process_test.py

示例15: work1

def work1():
    p = Subprocess(['sleep', '5'])
    future = p.wait_for_exit()

    ioloop.IOLoop.instance().add_future(future, finish_callback)
    print('work1: After add_future....')

    ioloop.IOLoop.instance().add_callback(dumy_callback)
    print ('work1: After add_callback...')
开发者ID:ideascf,项目名称:play,代码行数:9,代码来源:furture_play.py


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