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


Python Popen.wait方法代码示例

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


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

示例1: start_agent

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [as 别名]
    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,代码行数:29,代码来源:platformwrapper.py

示例2: do_job

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [as 别名]
    def do_job(self,jobid,props,*args,**kwargs):
        log.info("do job: %s"%(job))
        if props:
            props = json.loads(props)
        else:
            props = {}

        payload = {"id":jobid,"status":"building"}
        r = requests.post('%s/api/job'%(self.options.master_base_url),data=payload)
        log.info("update job %s status,result:%s"%(jobid,r))

        if props.has_key("steps"):
            steps = props["steps"]
            for step in steps:
                if step.has_key("shell"):
                    shell = step["shell"]
                    log.info("shell: %s"%(shell[:256]))
                    sub = Popen([shell], stdout=PIPE, stderr=PIPE, shell=True)

                    stdio_q = Queue()
                    def handle_stdout():
                        for l in sub.stdout:
                            stdio_q.put_nowait((0,l))
                    def handle_stderr():
                        for l in sub.stderr:
                            stdio_q.put_nowait((1,l))
                    def handle_stdio_q():
                        #stdout 0 stderr 1 extra 2 end 255
                        current_text_type = None
                        stdio_list = []
                        need_flush = False
                        timeout = None
                        while 1:
                            ttype,text = stdio_q.get()
                            if ttype!=current_text_type and len(stdio_list)>0:
                                need_flush = True
                            if len(stdio_list)>50:
                                need_flush = True
                            if need_flush:
                                text2flush = "".join(stdio_list)
                                payload = {"id":jobid,"text_type":current_text_type,"stdio_text":text2flush}
                                r = requests.post('%s/api/job'%(self.options.master_base_url),data=payload)
                                need_flush = False
                            if ttype==255:
                                break
                            current_text_type = ttype
                            stdio_list.append(text)
                    glet_stdout = gevent.spawn(handle_stdout)
                    glet_stderr = gevent.spawn(handle_stderr)
                    glet_stdio_q = gevent.spawn(handle_stdio_q)

                    sub.wait()
                    stdio_q.put_nowait((255,""))
                    glet_stdout.kill()
                    glet_stderr.kill()

        payload = {"id":jobid,"status":3}#JOB_STATUS_FINISHED
        r = requests.post('%s/api/job'%(self.options.master_base_url),data=payload)
        log.info("update job %d status,result:%s"%(jobid,r))
开发者ID:linciproject,项目名称:linci,代码行数:61,代码来源:worker.py

示例3: _cmd

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [as 别名]
def _cmd(cmdargs):
    """Executes the passed command.

    :param cmdargs: A list of arguments that should be passed to Popen.
    :type cmdargs: [str]
    """
    if verbose:
        print(cmdargs)
    process = Popen(cmdargs, env=os.environ, stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE)
    process.wait()
开发者ID:schandrika,项目名称:volttron,代码行数:13,代码来源:instance_setup.py

示例4: block_and_check_process_output

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [as 别名]
def block_and_check_process_output(process_args, fail_on_error=True, retry_count=0):
    process = Popen(process_args)
    process.wait()
    if process.returncode != 0:
        if retry_count > 0:
            print '{} failed. Retrying...'.format(' '.join(process_args))
            block_and_check_process_output(process_args, fail_on_error=fail_on_error, retry_count=retry_count-1)
        else:
            print process.stderr
            if fail_on_error:
                exit(1)
开发者ID:zulily,项目名称:zdutil,代码行数:13,代码来源:zdutil.py

示例5: block_until_sshable

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [as 别名]
def block_until_sshable(config, instance_name, tries=1, wait_time_seconds=10):
    if tries > 10:
        print "Tried {} times to ssh to {}, something bad happened".format(tries, instance_name)
        exit(1)

    process_args = zdgcutil.ssh(config, instance_name)
    process = Popen(process_args)
    process.wait()
    ret_code = process.returncode
    if ret_code != 0:
        print "{} not yet sshable, waiting {} seconds".format(instance_name, wait_time_seconds)
        time.sleep(wait_time_seconds)
        block_until_sshable(config, instance_name, tries + 1)
开发者ID:zulily,项目名称:zdutil,代码行数:15,代码来源:zdutil.py

示例6: test_cov_update_published

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [as 别名]
def test_cov_update_published(volttron_instance, test_agent):
    """Tests the functionality of BACnet change of value forwarding in the
    Master Driver and driver.py"""
    # Reset master driver config store
    cmd = ['volttron-ctl', 'config', 'delete', PLATFORM_DRIVER, '--all']
    process = Popen(cmd, env=volttron_instance.env,
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    result = process.wait()
    assert result == 0

    # Add fake device configuration
    cmd = ['volttron-ctl', 'config', 'store', PLATFORM_DRIVER,
           'fake.csv', 'examples/configurations/drivers/fake.csv', '--csv']
    process = Popen(cmd, env=volttron_instance.env,
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    result = process.wait()
    assert result == 0

    cmd = ['volttron-ctl', 'config', 'store', PLATFORM_DRIVER,
           "devices/fakedriver", 'examples/configurations/drivers/fake.config',
           '--json']
    process = Popen(cmd, env=volttron_instance.env,
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    result = process.wait()
    assert result == 0

    # install master driver, start the master driver, which starts the device
    master_uuid = volttron_instance.install_agent(
        agent_dir=get_services_core("MasterDriverAgent"),
        config_file={},
        start=True)
    print("agent id: ", master_uuid)

    # tell the master driver to forward the value
    point_name = "PowerState"
    device_path = "fakedriver"
    result_dict = {"fake1": "test", "fake2": "test", "fake3": "test"}
    test_agent.vip.rpc.call(PLATFORM_DRIVER, 'forward_bacnet_cov_value',
                            device_path, point_name, result_dict)
    # wait for the publishes to make it to the bus
    gevent.sleep(2)

    # Mock checks
    # Should have one "PowerState" publish for each item in the result dict
    # Total all publishes likely will include regular scrapes
    assert test_agent.cov_callback.call_count >= 3
    test_count = 0
    for call_arg in test_agent.cov_callback.call_args_list:
        if call_arg[0][5][0].get("PowerState", False):
            test_count += 1
    assert test_count == 3
开发者ID:Kisensum,项目名称:volttron,代码行数:53,代码来源:test_driver_bacnet_cov.py

示例7: github

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [as 别名]
def github():
    """ github回调 """
    deliveryid = request.headers.get('X-GitHub-Delivery', None)
    if deliveryid:
        signature = request.headers.get('X-Hub-Signature', None)
        if signature:
            hashtype, remotesignstr = signature.split('=')
            localsign = hmac.new(current_app.config['GITHUB_WEBHOOK_SECRET'], msg=request.data, digestmod=getattr(hashlib, hashtype))
            if remotesignstr != localsign.hexdigest():
                return jsonify({'error': 'no permission'}), 401
        event = request.headers.get('X-GitHub-Event', '')
        if event == 'push':
            subp = Popen('git checkout .;git pull', shell=True)
            subp.wait()
    return jsonify({})
开发者ID:yijunjun,项目名称:livetv_mining,代码行数:17,代码来源:views.py

示例8: _auction_fucn

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [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

示例9: test_drivenmatlabagent

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [as 别名]
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,代码行数:62,代码来源:test_drivengent.py

示例10: run_autobahn

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [as 别名]
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,代码行数:36,代码来源:run_autobahn_tests.py

示例11: proc

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [as 别名]
def proc(input, output, args, env=None, stderr=None):
	"""Run a subprocess, passing input to its stdin and sending its stdout to output,
	with each item newline-seperated.
	Args is either a string to be shell-interpreted, or a list of args.
	stderr is either not redirected (default), mixed in with stdout (pass subprocess.STDOUT),
	or redirected to a given file.
	"""
	from gevent.subprocess import Popen, PIPE, STDOUT

	if isinstance(args, unicode):
		args = args.encode('utf8')
	if isinstance(args, str):
		shell = True
	else:
		shell = False

	group = gevent.pool.Group()

	proc = None
	try:
		proc = Popen(args, shell=shell, env=env, stdin=PIPE, stdout=PIPE, stderr=stderr)

		@group.spawn
		def do_input():
			for item in input:
				item = item.encode('utf8') if isinstance(item, unicode) else str(item)
				proc.stdin.write('{}\n'.format(item))
				proc.stdin.flush()
			proc.stdin.close()

		@group.spawn
		def do_output():
			for line in proc.stdout:
				output.put(line.rstrip('\n'))
			output.close()

		proc.wait()
		group.join()
	finally:
		if proc and proc.poll() is None:
			try:
				proc.kill()
			except OSError as e:
				if e.errno != errno.ESRCH:
					raise
开发者ID:ekimekim,项目名称:pylibs,代码行数:47,代码来源:conc.py

示例12: start_agent

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [as 别名]
    def start_agent(self, agent_uuid):
        self.logit('Starting agent {}'.format(agent_uuid))
        self.logit("VOLTTRONO_HOME SETTING: {}".format(os.environ['VOLTTRON_HOME']))
        cmd = ['volttron-ctl', 'start', agent_uuid]
        p = Popen(cmd, env=self.env,
                  stdout=sys.stdout, stderr=sys.stderr)
        p.wait()

        # Confirm agent running
        cmd = ['volttron-ctl', 'status', agent_uuid]
        res = subprocess.check_output(cmd, env=self.env)
        assert 'running' in res
        pidpos = res.index('[') + 1
        pidend = res.index(']')
        pid = int(res[pidpos: pidend])

        self._started_pids.append(pid)
        return int(pid)
开发者ID:cbs-iiith,项目名称:volttron,代码行数:20,代码来源:platformwrapper.py

示例13: run_func

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [as 别名]
def run_func(queue, job_id, cmd, stop_on_failure=True):
    redirector = Redirector(_stream)
    _logrun(cmd)

    try:
        process = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=True)
        redirector.add_redirection("marteau-stdout", process, process.stdout)
        redirector.add_redirection("marteau-stderr", process, process.stderr)
        redirector.start()
        pid = process.pid
        queue.add_pid(job_id, pid)
        process.wait()
        res = process.returncode
        if res != 0 and stop_on_failure:
            _logrun("%r failed" % cmd)
            raise Exception("%r failed" % cmd)
        return res
    finally:
        redirector.kill()
        queue.remove_pid(job_id, pid)
开发者ID:whitmo,项目名称:marteau,代码行数:22,代码来源:job.py

示例14: exec_command

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [as 别名]
def exec_command(*args, **kwargs):
    shell = kwargs.get("shell", False)
    process = Popen(args, stdout=PIPE, stderr=PIPE, close_fds=True, shell=shell)
    
    retcode = process.wait()
    output = process.stdout.read()
    unused_err = process.stderr.read()

    if retcode:
        _logger.debug("Command '%s' returned non-zero exit status %d", args, retcode)
        
    return retcode, output.strip()
开发者ID:wraithallen,项目名称:sample_workflow_engine,代码行数:14,代码来源:worker.py

示例15: copper_node

# 需要导入模块: from gevent.subprocess import Popen [as 别名]
# 或者: from gevent.subprocess.Popen import wait [as 别名]
def copper_node(workdir):
    logpath = os.path.join(workdir, 'copper.log')
    unixpath = os.path.join(workdir, 'copper.sock')
    httppath = os.path.join(workdir, 'copper.http')
    confpath = os.path.join(workdir, 'copper.conf')
    config = {
        "listen": [
            {
                "net": "unix",
                "type": "http",
                "addr": httppath,
            },
            {
                "net": "unix",
                "addr": unixpath,
                "allow-changes": True,
            },
        ],
    }
    with open(confpath, 'w') as f:
        # YAML parses valid JSON data
        json.dump(config, f)
    with open(logpath, 'wb') as logfile:
        p = Popen(['copper-node', '-config=' + confpath], shell=False, cwd=workdir, stdout=logfile, stderr=logfile)
    try:
        while not os.path.exists(unixpath):
            time.sleep(0.001)
            rc = p.poll()
            if rc is not None:
                with open(logpath, 'rb') as logfile:
                    sys.stderr.write(logfile.read())
                raise RuntimeError('copper-node exited with status %r' % (rc,))
        yield {
            'unix': unixpath,
            'http': httppath,
        }
    finally:
        if p.poll() is None:
            p.terminate()
            p.wait()
开发者ID:snaury,项目名称:copper,代码行数:42,代码来源:conftest.py


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