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


Python Manager.add_process方法代码示例

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


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

示例1: test_events

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

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

    # subscribe to all events
    m.on('.', cb)

    testfile, cmd, args, wdir = dummy_cmd()
    m.add_process("dummy", cmd, args=args, cwd=wdir, numprocesses=4)
    m.ttin("dummy", 1)
    m.remove_process("dummy")

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


    assert ('create', 'dummy') in emitted
    assert ('start', 'dummy') in emitted
    assert ('update', 'dummy') in emitted
    assert ('stop', 'dummy') in emitted
    assert ('delete', 'dummy') in emitted
开发者ID:tilgovi,项目名称:gaffer,代码行数:28,代码来源:test_manager.py

示例2: test_manager_hooks

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import add_process [as 别名]
def test_manager_hooks():
    hooks = create_hooks(['create', 'start', 'update', 'stop',
        'delete', 'proc.dummy.start', 'proc.dummy.spawn',
        'proc.dummy.stop', 'proc.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()
    m.add_process("dummy", cmd, args=args, cwd=wdir, numprocesses=4)
    m.ttin("dummy", 1)
    m.remove_process("dummy")
    time.sleep(0.2)

    def on_stop(manager):
        s.stop()

    m.stop(on_stop)
    m.run()
    assert ('create', 'dummy') in emitted
    assert ('start', 'dummy') in emitted
    assert ('update', 'dummy') in emitted
    assert ('stop', 'dummy') in emitted
    assert ('delete', 'dummy') in emitted
    assert ('proc.dummy.start', 'dummy') in emitted
    assert ('proc.dummy.spawn', 'dummy') in emitted
    assert ('proc.dummy.stop', 'dummy') in emitted
    assert ('proc.dummy.exit', 'dummy') in emitted
开发者ID:metawake,项目名称:gaffer,代码行数:32,代码来源:test_webhooks.py

示例3: test_monitor

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import add_process [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

示例4: test_ttin

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import add_process [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

示例5: test_send_signal

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import add_process [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

示例6: test_flapping

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import add_process [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

示例7: test_start_multiple

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

    assert len(state.running) == 2

    m.stop()

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

示例8: test_start_stop_process

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

    assert len(state.running) == 1

    m.stop_process("dummy")
    assert len(state.running) == 0

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

示例9: test_simple_process

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

    assert state.numprocesses == 1
    assert state.name == "dummy"
    assert state.cmd == cmd
    assert state.settings['args'] == args
    assert state.settings['cwd'] == wdir

    m.remove_process("dummy")
    assert m.get_process_state("dummy") == None
    m.stop()
    m.run()
开发者ID:tilgovi,项目名称:gaffer,代码行数:19,代码来源:test_manager.py

示例10: test_numprocesses

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

    assert len(state.running) == 4
    state.numprocesses = 0
    assert state.numprocesses == 0

    m.manage_process("dummy")
    time.sleep(0.2)
    assert len(state.running) == 0
    m.stop()

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

示例11: test_processes_stats

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import add_process [as 别名]
def test_processes_stats():
    m = Manager()
    m.start()
    testfile, cmd, args, wdir = dummy_cmd()
    testfile1, cmd1, args1, wdir1 = dummy_cmd()
    m.add_process("a", cmd, args=args, cwd=wdir)
    time.sleep(0.2)
    infos = list(m.processes_stats())
    m.add_process("b", cmd, args=args, cwd=wdir)
    infos2 = list(m.processes_stats())
    m.stop()
    m.run()

    assert len(infos) == 1
    assert len(infos2) == 2

    assert infos[0]['name'] == "a"
    assert infos2[0]['name'] == "a"
    assert infos2[1]['name'] == "b"
开发者ID:tilgovi,项目名称:gaffer,代码行数:21,代码来源:test_manager.py

示例12: test_process_stats

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import add_process [as 别名]
def test_process_stats():
    m = Manager()
    m.start()
    testfile, cmd, args, wdir = dummy_cmd()
    m.add_process("dummy", cmd, args=args, cwd=wdir)
    time.sleep(0.2)
    info = m.get_process_stats("dummy")
    info_by_id = m.get_process_stats(1)
    pid = m.running[1].pid
    m.stop()
    m.run()

    assert isinstance(info, dict)
    assert isinstance(info_by_id, dict)
    assert "pid" in info_by_id
    assert info_by_id["pid"] == pid
    assert info['name'] == "dummy"
    assert len(info['stats']) == 1
    assert info['stats'][0]['pid'] == info_by_id['pid']
开发者ID:tilgovi,项目名称:gaffer,代码行数:21,代码来源:test_manager.py

示例13: test_process_id

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

    processes = state.list_processes()
    assert isinstance(processes, list)

    p = processes[0]
    assert isinstance(p, Process)
    assert p.id == 1

    p = processes[2]
    assert p.id == 3

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

示例14: test_group

# 需要导入模块: from gaffer.manager import Manager [as 别名]
# 或者: from gaffer.manager.Manager import add_process [as 别名]
def test_group():
    m = Manager()
    started = []
    stopped = []
    def cb(evtype, info):
        if evtype == "start":
            started.append(info['name'])
        elif evtype == "stop":
            stopped.append(info['name'])

    m.start()
    m.subscribe('start', cb)
    m.subscribe('stop', cb)
    testfile, cmd, args, wdir = dummy_cmd()
    m.add_process("ga:a", cmd, args=args, cwd=wdir, start=False)
    m.add_process("ga:b", cmd, args=args, cwd=wdir, start=False)
    m.add_process("gb:a", cmd, args=args, cwd=wdir, start=False)
    groups = sorted(m.get_groups())
    ga1 = m.get_group('ga')
    gb1 = m.get_group('gb')
    m.start_group("ga")
    m.stop_group("ga")
    time.sleep(0.2)
    m.remove_process("ga:a")
    ga2 = m.get_group('ga')
    m.stop_group("gb")

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

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

    assert groups == ['ga', 'gb']
    assert ga1 == ['ga:a', 'ga:b']
    assert gb1 == ['gb:a']
    assert started == ['ga:a', 'ga:b']
    assert stopped == ['ga:a', 'ga:b', 'gb:a']
    assert ga2 == ['ga:b']
开发者ID:tilgovi,项目名称:gaffer,代码行数:44,代码来源:test_manager.py

示例15: test_restart_manager

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

    def cb(manager):
        state = m.get_process_state("dummy")
        results.append(state.pids)
        m.stop()

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

    assert results[0] != results[1]
开发者ID:tilgovi,项目名称:gaffer,代码行数:22,代码来源:test_manager.py


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