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


Python subprocess.Popen类代码示例

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


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

示例1: get_doc_index

def get_doc_index(document, filepath):
    words = {}
    command = 'tesseract ' + filepath + ' -l hrv stdout'
    #text = subprocess.check_output(command, shell=True)
    print '>>> ', command
    sub = Popen([command], stdout=PIPE, shell=True)
    text, err = sub.communicate()
    print '>>> ', command, 'DONE'
    # extract page num from file path
    match = re.search('.*xl-(\d+).png', filepath)
    if match:
        page = int(match.groups()[0])
    for word in text.strip().split():
        # skip small words
        if len(word) <= 2:
            continue
        if word in words:
            document_dict = words[word]
            if document['name'] in document_dict:
                pages_set = words[word][document['name']]
                pages_set.add(page)
                words[word][document['name']] = pages_set
            else:
                words[word][document['name']] = set([page])
        else:
            # init word
            words[word] = {document['name']: set([page])}
    return len(words)
开发者ID:klemo,项目名称:covermania,代码行数:28,代码来源:gen.py

示例2: ping

def ping(ip, task_id):
    loss = latency = None
    p = Popen(['ping', '-c', '3', ip], stdout=PIPE, stderr=PIPE) 
    out, err = p.communicate()
    out = out.split('\n')
    for line in out:
	line = line.rstrip()
        match = re.match('.* ([0-9]+)% packet loss.*', line)
        if match:
	    loss = match.group(1)

        match = re.match('.*([0-9\.]+)/([0-9\.]+)/([0-9\.])+/([0-9\.]+) ms.*', line)
        if match:
	    latency = match.group(2)
    ping = Ping()
    ping.ip = ip
    ping.task_id = uuid.UUID(task_id)

    if loss:
        ping.loss = loss

    if latency:
        ping.latency = float(latency)

    ping.save()
开发者ID:huzichunjohn,项目名称:ping,代码行数:25,代码来源:worker.py

示例3: test_ia_upload

def test_ia_upload():
    # upload from stdin.
    cmd = ('echo "Hello World!" |'
           'ia upload iacli-test-item - --remote-name="stdin.txt" --size-hint=8')
    proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    stdout, stderr = proc.communicate()
    assert proc.returncode == 0

    cmd = ('echo "Hello World!" |'
           'ia upload iacli-test-item -')
    proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    stdout, stderr = proc.communicate()
    assert proc.returncode == 1
    assert stderr == '--remote-name is required when uploading from stdin.\n'

    # upload file.
    cmd = 'ia upload iacli-test-item setup.py'
    proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    stdout, stderr = proc.communicate()
    assert proc.returncode == 0

    # upload debug.
    cmd = 'ia upload iacli-test-item setup.py --debug'
    proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    stdout, stderr = proc.communicate()
    assert proc.returncode == 0

    # upload non-200 status_code.
    cmd = ('echo "Hello World!" |'
           'ia upload iacli-test-item - --remote-name="iacli-test-item_meta.xml"')
    proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    stdout, stderr = proc.communicate()
    assert stderr == 'error "AccessDenied" (403): Access Denied\n'
    assert proc.returncode == 1
开发者ID:saper,项目名称:ia-wrapper,代码行数:34,代码来源:test_ia_upload.py

示例4: worker

def worker():
    print 'start'
    sub = Popen(['sleep 10'], stdout=PIPE, shell=True)
#    sub = Popen(['top'], stdout=PIPE, shell=True)
    out, err = sub.communicate()
    print 'end'
    return out.rstrip()
开发者ID:lizhenfen,项目名称:python,代码行数:7,代码来源:gevent_use.py

示例5: _auction_fucn

 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,代码行数:27,代码来源:chronograph.py

示例6: start_agent

    def start_agent(self, agent_uuid):
        self.logit('Starting agent {}'.format(agent_uuid))
        self.logit("VOLTTRON_HOME SETTING: {}".format(
            self.env['VOLTTRON_HOME']))
        cmd = ['volttron-ctl']
        cmd.extend(['start', agent_uuid])
        p = Popen(cmd, env=self.env,
                  stdout=sys.stdout, stderr=sys.stderr)
        p.wait()

        # Confirm agent running
        cmd = ['volttron-ctl']
        cmd.extend(['status', agent_uuid])
        res = subprocess.check_output(cmd, env=self.env)
        # 776 TODO: Timing issue where check fails
        time.sleep(.1)
        self.logit("Subprocess res is {}".format(res))
        assert 'running' in res
        pidpos = res.index('[') + 1
        pidend = res.index(']')
        pid = int(res[pidpos: pidend])

        assert psutil.pid_exists(pid), \
            "The pid associated with agent {} does not exist".format(pid)

        self.started_agent_pids.append(pid)
        return pid
开发者ID:schandrika,项目名称:volttron,代码行数:27,代码来源:platformwrapper.py

示例7: logs_downloader

        def logs_downloader(logs_queued, recipient):
            # Build tar command with tar command and logs sent by client
            archive_path = '%ssrc/rockstor/logs/' % settings.ROOT_DIR
            archive_file = 'requested_logs.tgz'

            # If log download requested by Log Reader serve a personalized tgz
            # file with log file name
            if (recipient == 'reader_response'):
                archive_file = '%s.tgz' % logs_queued[0]
            archive_path += archive_file
            download_command = []
            download_command.extend(self.tar_utility)
            download_command.append(archive_path)

            # Get every log location via logs dictionary
            for log in logs_queued:
                download_command.append(self.build_log_path(log))

            # Build download archive
            download_process = Popen(download_command, bufsize=1, stdout=PIPE)
            download_process.communicate()

            # Return ready state for logs archive download specifying recipient
            # (logManager or LogDownloader)
            self.emit('logsdownload',
                      {
                          'key': 'logManager:logsdownload', 'data': {
                              'archive_name': '/logs/%s' % archive_file,
                              'recipient': recipient
                          }
                      })
开发者ID:priyaganti,项目名称:rockstor-core,代码行数:31,代码来源:data_collector.py

示例8: run_autobahn

def run_autobahn():
    """
    Spawn the autobahn test suite in a subprocess
    """
    import os.path

    cmd = ['wstest -m fuzzingclient -s %s/autobahn.json' % (
        os.path.dirname(__file__),)]

    wstest = Popen(cmd, stderr=PIPE, stdout=PIPE, shell=True)

    if wstest.wait():
        # something went wrong, it's boom time.
        stdout, stderr = wstest.communicate(None)

        sys.stderr.write(stderr)
        sys.stderr.flush()

        sys.stdout.write(stdout)
        sys.stderr.flush()

        raise RuntimeError

    # parse the generated report to see if we have failures
    chk = Popen(
        'fgrep gevent_websocket reports/clients/index.html | grep Fail',
        stdout=PIPE, shell=True)

    stdout, stderr = chk.communicate(None)

    if stdout:
        sys.stderr.write('Autobahn test failures:\n' + stdout)

        raise SystemExit(1)
开发者ID:duego,项目名称:gevent-websocket,代码行数:34,代码来源:run_autobahn_tests.py

示例9: link_alive_tcp

def link_alive_tcp( link, remote_ip ):
    """
    Returns status of the link.
    If the link is alive, returns its rtt to the remote_ip.
    
    Use this method to check if the link is alive:

        $ nc -v -s 192.168.0.101 -w 1 1.1.1.1 35501 
        nc: connect to 1.1.1.1 port 35501 (tcp) timed out: Operation now in progress
        $ nc -v -s 192.168.0.101 -w 1 5.9.243.189 35501 
        nc: connect to 5.9.243.189 port 35501 (tcp) failed: Connection refused

    """

    if link[0] in 'el':
        source_ip = ip_of_interface( link )
        if source_ip is None:
            log("Can't detect IP address of %s" % link)
            return

    cmd = ['nc', '-v', '-s', source_ip, '-w', '1', remote_ip, '35501' ]
    p = Popen(cmd, stdout=PIPE, stderr=STDOUT)
    stdout = p.communicate()[0]

    if 'Connection refused' in stdout:
        return '1'
    return None
开发者ID:chubin,项目名称:rpi-homerouter,代码行数:27,代码来源:pinger.py

示例10: execute_cmd_with_output

def execute_cmd_with_output(cmd, stdin=None):
    log.debug("Running command: %r" % cmd)
    p = Popen(cmd, bufsize=-1, stdout=PIPE, stderr=PIPE, stdin=stdin)
    (msgs, errs) = p.communicate()
    if p.returncode != 0:
        raise Exception('Failed to run command')
    return (msgs, errs)
开发者ID:gabriel-samfira,项目名称:jrunner,代码行数:7,代码来源:__init__.py

示例11: save_weather_data

def save_weather_data( location, filename ):

    if location == NOT_FOUND_LOCATION:
        location_not_found = True
        location = DEFAULT_LOCATION
    else:
        location_not_found = False
    
    p = Popen( [ WEGO, '--city=%s' % location ], stdout=PIPE, stderr=PIPE )
    stdout, stderr = p.communicate()
    if p.returncode != 0:
        error( stdout + stderr )

    dirname = os.path.dirname( filename )
    if not os.path.exists( dirname ):
        os.makedirs( dirname )
    
    if location_not_found:
        stdout += NOT_FOUND_MESSAGE

    open( filename, 'w' ).write( stdout )

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

    open( filename+'.html', 'w' ).write( stdout )
开发者ID:Galen-Titanium,项目名称:wttr.in,代码行数:28,代码来源:srv.py

示例12: call_subprocess

 def call_subprocess(self, cmd):
     times = datetime.datetime.now()
     # latest 14.0.4 requires "HOME" env variable to be passed
     # copy current environment variables and add "HOME" variable
     # pass the newly created environment variable to Popen subprocess
     env_home = os.environ.copy()
     env_home['HOME'] = HOME_ENV_PATH
     # stdout and stderr are redirected.
     # stderr not used (stdout validation is done so stderr check is
     # is not needed)
     try:
         p = Popen(cmd, stdout=PIPE, \
             stderr=PIPE, shell=True, env=env_home)
         while p.poll() is None:
             gevent.sleep(0.1)
             now = datetime.datetime.now()
             diff = now - times
             if diff.seconds > 5:
                 os.kill(p.pid, signal.SIGKILL)
                 os.waitpid(-1, os.WNOHANG)
                 message = "command:" + cmd + " ---> hanged"
                 ssdlog = StorageStatsDaemonLog(message = message)
                 self.call_send(ssdlog)
                 return None
     except:
         pass
         return None
     # stdout is used
     return p.stdout.read()
开发者ID:morganwang010,项目名称:contrail-controller,代码行数:29,代码来源:storage_nodemgr.py

示例13: ipv6_supported

def ipv6_supported():
    """Checks whether we can support IPv6 on this host.

    :returns tuple[bool,str]: supported, reason for lack of support or None.
    """
    if not os.path.exists("/proc/sys/net/ipv6"):
        return False, "/proc/sys/net/ipv6 is missing (IPv6 compiled out?)"
    try:
        check_call(["which", "ip6tables"])
    except FailedSystemCall:
        return False, ("ip6tables not installed; Calico IPv6 support requires "
                       "Linux kernel v3.3 or above and ip6tables v1.4.14 or "
                       "above.")
    try:
        # Use -C, which checks for a particular rule.  We don't expect the rule
        # to exist but iptables will give us a distinctive error if the
        # rpfilter module is missing.
        proc = Popen(["ip6tables", "-C", "FORWARD", "-m", "rpfilter"],
                     stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, err = proc.communicate()
        if "Couldn't load match" in err:
            return False, (
                "ip6tables is missing required rpfilter match module; "
                "Calico IPv6 support requires Linux kernel v3.3 or "
                "above and ip6tables v1.4.14 or above."
            )
    except OSError:
        return False, "Failed to execute ip6tables"
    return True, None
开发者ID:elfchief,项目名称:calico,代码行数:29,代码来源:futils.py

示例14: try_get_video_name

 def try_get_video_name(self, video_url):
     print "Getting name for %s"%video_url
     cmd=['youtube-dl', '--get-title',video_url]
     temp = Popen(cmd, stdout=PIPE)
     out, err = temp.communicate()
     print out
     return out 
开发者ID:innosam,项目名称:raspberry-play,代码行数:7,代码来源:player.py

示例15: test_drivenmatlabagent

def test_drivenmatlabagent(volttron_instance1):
    print("** Setting up test_drivenagent module **")
    
    wrapper = volttron_instance1
    
    #Write config files for master driver
    process = Popen(['python', 'config_builder.py', 
                     '--count=1', 
                     '--publish-only-depth-all',
                     '--campus=fakecampus',
                     '--building=fakebuilding',
                     '--interval=5',
                     '--config-dir=../../applications/pnnl/FakeDrivenMatlabAgent/tests',
                     'fake', 
                     '../../applications/pnnl/FakeDrivenMatlabAgent/tests/test_fake.csv', 
                     'null'], 
                    env=volttron_instance1.env, cwd='scripts/scalability-testing',
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    result = process.wait()
    print result
    assert result == 0
     
    #Actuator Agent
    agent_uuid = volttron_instance1.install_agent(
        agent_dir="services/core/ActuatorAgent",
        config_file="services/core/ActuatorAgent/actuator-deploy.service",
        start=True)
    print("agent id: ", agent_uuid)
    assert agent_uuid
    actuator_agent = wrapper.build_agent()
     
    #Driven Matlab Agent
    agent_uuid = volttron_instance1.install_agent(
        agent_dir="applications/pnnl/FakeDrivenMatlabAgent",
        config_file=config_wh,
        start=True)
    print("agent id: ", agent_uuid)
    assert agent_uuid
    driven_agent = wrapper.build_agent()
     
    #Fake Master Driver
    agent_uuid = volttron_instance1.install_agent(
        agent_dir="services/core/MasterDriverAgent",
        config_file="applications/pnnl/FakeDrivenMatlabAgent/tests/master-driver.agent",
        start=True)
    print("agent id: ", agent_uuid)
    assert agent_uuid
    driver_agent = wrapper.build_agent()
     
    gevent.sleep(5)
     
    path = 'fakecampus/fakebuilding/fakedriver0/HPWH_Phy0_PowerState'
    value = driven_agent.vip.rpc.call('platform.actuator', 'get_point', path).get()
    print('The set point value is '+str(value))
    assert value == 1 
     
    path = 'fakecampus/fakebuilding/fakedriver0/ERWH_Phy0_ValveState'
    value = driven_agent.vip.rpc.call('platform.actuator', 'get_point', path).get()
    print('The set point value is '+str(value))
    assert value == 1 
开发者ID:VOLTTRON,项目名称:volttron-applications,代码行数:60,代码来源:test_drivengent.py


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