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


Python Manager.run方法代码示例

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


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

示例1: test_monitor

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_monitor():
    m = Manager()
    monitored = []
    def cb(evtype, info):
        monitored.append((evtype, info))

    m.start()
    testfile, cmd, args, wdir = dummy_cmd()
    m.add_process("a", cmd, args=args, cwd=wdir)
    time.sleep(0.2)
    pid = m.running[1].pid
    m.monitor("a", cb)

    def stop(handle):
        m.unmonitor("a", cb)
        m.stop()

    t = pyuv.Timer(m.loop)
    t.start(stop, 0.3, 0.0)

    m.run()
    assert len(monitored) >= 1
    res = monitored[0]
    assert res[0] == "stat"
    assert "cpu" in res[1]
    assert res[1]["pid"] == pid
开发者ID:tilgovi,项目名称:gaffer,代码行数:28,代码来源:test_manager.py

示例2: test_ttin

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_ttin():
    m = Manager()
    m.start()
    testfile, cmd, args, wdir = dummy_cmd()
    m.add_process("dummy", cmd, args=args, cwd=wdir, numprocesses=1)
    state = m.get_process_state("dummy")

    assert len(state.running) == 1
    ret = m.ttin("dummy", 1)
    assert ret == 2

    time.sleep(0.2)
    assert len(state.running) == 2

    ret = m.ttin("dummy", 1)
    assert ret == 3

    time.sleep(0.2)
    assert len(state.running) == 3


    ret = m.ttin("dummy", 3)
    assert ret == 6

    time.sleep(0.2)
    assert len(state.running) == 6

    m.stop()
    m.run()
开发者ID:tilgovi,项目名称:gaffer,代码行数:31,代码来源:test_manager.py

示例3: test_scalein

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_scalein():
    m = Manager()
    m.start()
    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("dummy", cmd, args=args, cwd=wdir, numprocesses=1)
    m.load(config)
    state = m._get_locked_state("dummy")

    assert len(state.running) == 1
    ret = m.scale("dummy", 1)
    assert ret == 2

    time.sleep(0.2)
    assert len(state.running) == 2

    ret = m.scale("dummy", 1)
    assert ret == 3

    time.sleep(0.2)
    assert len(state.running) == 3


    ret = m.scale("dummy", 3)
    assert ret == 6

    time.sleep(0.2)
    assert len(state.running) == 6

    m.stop()
    m.run()
开发者ID:adamchainz,项目名称:gaffer,代码行数:32,代码来源:test_manager.py

示例4: test_manager_hooks

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_manager_hooks():
    hooks = create_hooks(['load', 'unload', 'start', 'update', 'stop',
        'job.default.dummy.start', 'job.default.dummy.spawn',
        'job.default.dummy.stop', 'job.default.dummy.exit'])
    emitted = []
    loop = pyuv.Loop.default_loop()
    s = get_server(loop, emitted)
    s.start()
    m = Manager(loop=loop)
    m.start(apps=[WebHooks(hooks)])
    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("dummy", cmd, args=args, cwd=wdir, numprocesses=1)
    m.load(config)
    m.manage("dummy")
    m.scale("dummy", 1)
    m.unload("dummy")

    t = pyuv.Timer(loop)

    def on_stop(manager):
        t.start(lambda h: s.stop(), 0.4, 0.0)

    m.stop(on_stop)

    m.run()
    assert ('load', 'default.dummy') in emitted
    assert ('start', 'default.dummy') in emitted
    assert ('update', 'default.dummy') in emitted
    assert ('stop', 'default.dummy') in emitted
    assert ('unload', 'default.dummy') in emitted
    assert ('job.default.dummy.start', 'default.dummy') in emitted
    assert ('job.default.dummy.spawn', 'default.dummy') in emitted
    assert ('job.default.dummy.stop', 'default.dummy') in emitted
    assert ('job.default.dummy.exit', 'default.dummy') in emitted
开发者ID:adamchainz,项目名称:gaffer,代码行数:36,代码来源:test_webhooks.py

示例5: test_process_events

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_process_events():
    emitted = []
    m = Manager()
    m.start()

    def cb(ev, *args):
        emitted.append(ev)

    # subscribe to all events
    chan = m.subscribe("JOB:default.dummy")
    chan.bind_all(cb)

    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("dummy", cmd, args=args, cwd=wdir)
    m.load(config)
    m.unload(config)

    time.sleep(0.2)
    m.stop()
    m.run()

    assert 'start' in emitted
    assert 'spawn' in emitted
    assert 'stop' in emitted
    assert 'exit' in emitted
开发者ID:adamchainz,项目名称:gaffer,代码行数:27,代码来源:test_channel.py

示例6: test_stats

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_stats():
    m = Manager()
    monitored = []
    def cb(info):
        monitored.append(info)

    m.start()
    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("a", cmd, args=args, cwd=wdir)
    m.load(config)
    os_pid = m.running[1].os_pid

    chan = m.subscribe("STATS:default.a")
    chan.bind(cb)

    def stop(handle):
        chan.unbind(cb)
        m.stop()

    t = pyuv.Timer(m.loop)
    t.start(stop, 0.3, 0.0)

    m.run()
    assert len(monitored) >= 1
    res = monitored[0]
    assert "cpu" in res
    assert res["os_pid"] == os_pid
开发者ID:adamchainz,项目名称:gaffer,代码行数:29,代码来源:test_channel.py

示例7: test_flapping

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_flapping():
    m = Manager()
    m.start()
    cmd, args, wdir = crash_cmd()
    flapping = FlappingInfo(attempts=1, window=1, retry_in=0.1, max_retry=2)
    m.add_process("crashing", cmd, args=args, cwd=wdir, flapping=flapping)
    state = m.get_process_state("crashing")

    def cb(handle):
        handle.stop()
        assert state.stopped == True

    t = pyuv.Timer(m.loop)
    t.start(cb, 0.8, 0.8)
    m.add_process("crashing2", cmd, args=args, cwd=wdir)
    state = m.get_process_state("crashing2")

    def cb1(handle):
        handle.stop()
        assert state.stopped == False

    t = pyuv.Timer(m.loop)
    t.start(cb1, 0.8, 0.8)

    m.stop()
    m.run()
开发者ID:metawake,项目名称:gaffer,代码行数:28,代码来源:test_manager.py

示例8: test_basic

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_basic():
    emitted = []
    m = Manager()
    m.start()

    def cb(ev, msg):
        emitted.append((ev, msg['name']))

    # subscribe to all events
    chan = m.subscribe("EVENTS")
    chan.bind('.', cb)

    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("dummy", cmd, args=args, cwd=wdir, numprocesses=4)
    m.load(config)
    m.scale("dummy", 1)
    m.unload("dummy")

    time.sleep(0.2)
    m.stop()
    m.run()

    assert ('load', 'default.dummy') in emitted
    assert ('start', 'default.dummy') in emitted
    assert ('update', 'default.dummy') in emitted
    assert ('stop', 'default.dummy') in emitted
    assert ('unload', 'default.dummy') in emitted
开发者ID:adamchainz,项目名称:gaffer,代码行数:29,代码来源:test_channel.py

示例9: test_send_signal

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_send_signal():
    m = Manager()
    m.start()
    testfile, cmd, args, wdir = dummy_cmd()
    m.add_process("dummy", cmd, args=args, cwd=wdir)
    time.sleep(0.2)
    state = m.get_process_state("dummy")
    processes = state.list_processes()
    m.send_signal("dummy", signal.SIGHUP)
    time.sleep(0.2)

    m.send_signal(processes[0].id, signal.SIGHUP)
    m.stop_process("dummy")

    def stop(handle):
        handle.stop()
        m.stop()

    t = pyuv.Timer(m.loop)
    t.start(stop, 0.8, 0.0)
    m.run()

    with open(testfile, 'r') as f:
        res = f.read()
        assert res == 'STARTHUPHUPQUITSTOP'
开发者ID:tilgovi,项目名称:gaffer,代码行数:27,代码来源:test_manager.py

示例10: test_send_signal

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_send_signal():
    m = Manager()
    m.start()
    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("dummy", cmd, args=args, cwd=wdir)
    m.load(config)
    time.sleep(0.2)

    m.killall("dummy", signal.SIGHUP)
    time.sleep(0.2)


    with pytest.raises(ProcessError) as e:
        m.killall("dummy1", signal.SIGHUP)
        assert e.errno == 404

    m.stop_job("dummy")

    def stop(handle):
        handle.stop()
        m.stop()

    t = pyuv.Timer(m.loop)
    t.start(stop, 0.8, 0.0)
    m.run()

    with open(testfile, 'r') as f:
        res = f.read()
        assert res == 'STARTHUPQUITSTOP'
开发者ID:adamchainz,项目名称:gaffer,代码行数:31,代码来源:test_manager.py

示例11: test_monitor

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_monitor():
    m = Manager()
    monitored = []
    def cb(evtype, info):
        monitored.append((evtype, info))

    m.start()
    testfile, cmd, args, wdir = dummy_cmd()
    configa = ProcessConfig("a", cmd, args=args, cwd=wdir)
    m.load(configa)
    time.sleep(0.2)
    os_pid = m.running[1].os_pid
    m.monitor(cb, "a")

    def stop(handle):
        m.unmonitor(cb, "a")
        m.stop()

    t = pyuv.Timer(m.loop)
    t.start(stop, 0.3, 0.0)

    m.run()
    assert len(monitored) >= 1
    res = monitored[0]
    assert res[0] == "stat"
    assert "cpu" in res[1]
    assert res[1]["os_pid"] == os_pid
开发者ID:adamchainz,项目名称:gaffer,代码行数:29,代码来源:test_manager.py

示例12: test_priority

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_priority():
    m = Manager()
    started = []
    def cb(evtype, info):
        started.append(info['name'])

    m.start()
    m.events.subscribe('start', cb)

    testfile, cmd, args, wdir = dummy_cmd()
    a = ProcessConfig("a", cmd, args=args, cwd=wdir)
    b = ProcessConfig("b", cmd, args=args, cwd=wdir)
    c = ProcessConfig("c", cmd, args=args, cwd=wdir)


    m.load(a, start=False)
    m.load(b, start=False)
    m.load(c, start=False)

    # start all processes
    m.jobs_walk(lambda mgr, label: mgr.start_job(label))

    def stop(handle):
        m.events.unsubscribe("start", cb)
        m.stop()

    t = pyuv.Timer(m.loop)
    t.start(stop, 0.4, 0.0)
    m.run()

    assert started == ["default.a", "default.b", "default.c"]
开发者ID:adamchainz,项目名称:gaffer,代码行数:33,代码来源:test_manager.py

示例13: test_processes_stats

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_processes_stats():

    def collect_cb(inf, m, name):
        inf.append(m.stats(name))

    m = Manager()
    m.start()
    testfile, cmd, args, wdir = dummy_cmd()
    testfile1, cmd1, args1, wdir1 = dummy_cmd()
    configa = ProcessConfig("a", cmd, args=args, cwd=wdir)
    m.load(configa)

    time.sleep(0.2)
    infos = []
    infos2 = []
    m.jobs_walk(partial(collect_cb, infos))
    configb = ProcessConfig("b", cmd, args=args, cwd=wdir)
    m.load(configb)
    m.jobs_walk(partial(collect_cb, infos2))
    m.stop()
    m.run()

    assert len(infos) == 1
    assert len(infos2) == 2
    assert infos[0]['name'] == "default.a"
    assert infos2[0]['name'] == "default.a"
    assert infos2[1]['name'] == "default.b"
开发者ID:adamchainz,项目名称:gaffer,代码行数:29,代码来源:test_manager.py

示例14: test_process_exit_event

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_process_exit_event():
    emitted = []
    m = Manager()
    m.start()

    def cb(ev, msg):
        emitted.append(msg)

    # subscribe to all events
    m.events.subscribe('job.default.dummy.exit', cb)

    testfile, cmd, args, wdir = dummy_cmd()
    config = ProcessConfig("dummy", cmd, args=args, cwd=wdir)
    m.load(config)
    m.unload("dummy")

    time.sleep(0.2)
    m.stop()
    m.run()

    assert len(emitted) == 1
    assert len(emitted[0]) == 7

    msg = emitted[0]
    assert "exit_status" in msg
    assert msg['once'] == False
开发者ID:adamchainz,项目名称:gaffer,代码行数:28,代码来源:test_manager.py

示例15: test_flapping

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import run [as 别名]
def test_flapping():
    m = Manager()
    m.start()
    states = []
    cmd, args, wdir = crash_cmd()

    # create flapping info object
    flapping = FlappingInfo(attempts=1., window=1, retry_in=0.1,
            max_retry=1)

    # load conf
    conf1 = ProcessConfig("crashing", cmd, args=args, cwd=wdir,
            flapping=flapping)
    conf2 = ProcessConfig("crashing2", cmd, args=args, cwd=wdir)
    m.load(conf1)
    m.load(conf2)

    time.sleep(0.2)

    def cb(handle):
        state = m._get_locked_state("crashing")
        states.append(state.stopped)
        state2 = m._get_locked_state("crashing2")
        states.append(state2.stopped)
        m.stop()

    t = pyuv.Timer(m.loop)
    t.start(cb, 0.8, 0.0)
    m.run()

    assert states == [True, False]
开发者ID:adamchainz,项目名称:gaffer,代码行数:33,代码来源:test_manager.py


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