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


Python ModelBroadcaster.cmd方法代码示例

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


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

示例1: test_timeout

# 需要导入模块: from gnome.multi_model_broadcast import ModelBroadcaster [as 别名]
# 或者: from gnome.multi_model_broadcast.ModelBroadcaster import cmd [as 别名]
def test_timeout(secs, timeout, expected_runtime, valid_func):
    model = make_model()

    model_broadcaster = ModelBroadcaster(model,
                                         ('down', 'normal', 'up'),
                                         ('down', 'normal', 'up'))

    try:
        print '\nsleeping for {} secs...'.format(secs)
        if timeout is None:
            begin = time.time()
            res = model_broadcaster.cmd('sleep', {'secs': secs})
            end = time.time()
        else:
            begin = time.time()
            res = model_broadcaster.cmd('sleep', {'secs': secs},
                                        timeout=timeout)
            end = time.time()

        rt = end - begin

        # runtime duraton should be either:
        # - the expected response time plus a bit of overhead
        # - the expected timeout plus a bit of overhead
        print 'runtime: ', rt
        assert rt >= expected_runtime
        assert rt < expected_runtime + (expected_runtime * 0.06)

        assert valid_func(res)
    finally:
        model_broadcaster.stop()
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:33,代码来源:test_model_multiproc.py

示例2: test_timeout_2_times

# 需要导入模块: from gnome.multi_model_broadcast import ModelBroadcaster [as 别名]
# 或者: from gnome.multi_model_broadcast.ModelBroadcaster import cmd [as 别名]
def test_timeout_2_times():
    model = make_model()

    model_broadcaster = ModelBroadcaster(model,
                                         ('down', 'normal', 'up'),
                                         ('down', 'normal', 'up'))

    try:
        #
        # First, we set a short timeout for a command, but a shorter command.
        # The command should succeed
        #
        secs, timeout, expected_runtime = 4, 5, 4
        print '\nsleeping for {} secs...'.format(secs)

        begin = time.time()
        res = model_broadcaster.cmd('sleep', {'secs': secs}, timeout=timeout)
        end = time.time()

        rt = end - begin

        assert rt >= expected_runtime
        assert rt < expected_runtime + (expected_runtime * 0.06)
        assert is_valid(res)

        #
        # Next, run a command with no timeout specified.  The timeout should
        # have reverted back to the default, and the command should succeed.
        #
        secs, expected_runtime = 9, 9
        print '\nsleeping for {} secs...'.format(secs)

        begin = time.time()
        res = model_broadcaster.cmd('sleep', {'secs': secs})
        end = time.time()

        rt = end - begin

        assert rt >= expected_runtime
        assert rt < expected_runtime + (expected_runtime * 0.06)
        assert is_valid(res)

    finally:
        model_broadcaster.stop()
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:46,代码来源:test_model_multiproc.py

示例3: test_uncertainty_array_indexing

# 需要导入模块: from gnome.multi_model_broadcast import ModelBroadcaster [as 别名]
# 或者: from gnome.multi_model_broadcast.ModelBroadcaster import cmd [as 别名]
def test_uncertainty_array_indexing():
    model = make_model()

    model_broadcaster = ModelBroadcaster(model,
                                         ('down', 'normal', 'up'),
                                         ('down', 'normal', 'up'))

    try:
        res = model_broadcaster.cmd('get_wind_timeseries', {},
                                    ('down', 'down'))
        assert np.allclose([r[0] for r in res], 17.449237)

        res = model_broadcaster.cmd('get_spill_amounts', {}, ('down', 'down'))
        assert np.isclose(res[0], 333.33333)

        res = model_broadcaster.cmd('get_wind_timeseries', {}, ('up', 'up'))
        assert np.allclose([r[0] for r in res], 20.166224)

        res = model_broadcaster.cmd('get_spill_amounts', {}, ('up', 'up'))
        assert np.isclose(res[0], 1666.66666)
    finally:
        model_broadcaster.stop()
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:24,代码来源:test_model_multiproc.py

示例4: test_weathering_output_only

# 需要导入模块: from gnome.multi_model_broadcast import ModelBroadcaster [as 别名]
# 或者: from gnome.multi_model_broadcast.ModelBroadcaster import cmd [as 别名]
def test_weathering_output_only():
    model = make_model(geojson_output=True)

    model_broadcaster = ModelBroadcaster(model,
                                         ('down', 'normal', 'up'),
                                         ('down', 'normal', 'up'))

    print '\nOutputter results:'
    res = model_broadcaster.cmd('get_outputters', {})

    assert not [o for r in res for o in r
                if not isinstance(o, WeatheringOutput)]

    print '\nStep results:'
    res = model_broadcaster.cmd('step', {})

    assert len(res) == 9

    # added a 'valid' flag to output
    assert [r.keys() for r in res
            if len(r.keys()) == 2
            and 'WeatheringOutput' in r]

    model_broadcaster.stop()
开发者ID:axiom-data-science,项目名称:PyGnome,代码行数:26,代码来源:test_model_multiproc.py

示例5: WeatheringOutput

# 需要导入模块: from gnome.multi_model_broadcast import ModelBroadcaster [as 别名]
# 或者: from gnome.multi_model_broadcast.ModelBroadcaster import cmd [as 别名]
    model.outputters += WeatheringOutput()

    return model


if __name__ == '__main__':
    scripting.make_images_dir()

    model = make_model()

    model_broadcaster = ModelBroadcaster(model,
                                         ('down', 'normal', 'up'),
                                         ('down', 'normal', 'up'))

    print '\nStep results:'
    pp.pprint(model_broadcaster.cmd('step', {}))

    print '\nGetting wind timeseries for all models:'
    pp.pprint(model_broadcaster.cmd('get_wind_timeseries', {}))

    print '\nGetting spill amounts for all models:'
    pp.pprint(model_broadcaster.cmd('get_spill_amounts', {}))

    print '\nGetting time & spill values for just the (down, down) model:'
    pp.pprint((model_broadcaster.cmd('get_wind_timeseries', {},
                                     ('down', 'down')),
               model_broadcaster.cmd('get_spill_amounts', {},
                                     ('down', 'down')),
               ))

    print '\nGetting time & spill values for just the (normal, normal) model:'
开发者ID:NOAA-ORR-ERD,项目名称:PyGnome,代码行数:33,代码来源:script_weathering_mp.py


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