本文整理汇总了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()
示例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()
示例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()
示例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()
示例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:'