• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python base.SimpleExecutor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mirakuru.base.SimpleExecutor的典型用法代码示例。如果您正苦于以下问题:Python SimpleExecutor类的具体用法?Python SimpleExecutor怎么用?Python SimpleExecutor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_running_context

def test_running_context():
    """Start process and shuts it down."""
    executor = SimpleExecutor(sleep_300)
    with executor:
        assert executor.running() is True

    assert executor.running() is False
开发者ID:jotes,项目名称:mirakuru,代码行数:7,代码来源:test_executor.py


示例2: test_forgotten_stop

def test_forgotten_stop():
    """
    Test if SimpleExecutor subprocess is killed after an instance is deleted.

    Existence can end because of context scope end or by calling 'del'.
    If someone forgot to stop() or kill() subprocess it should be killed
    by default on instance cleanup.
    """
    mark = str(uuid.uuid1())
    # We cannot simply do `sleep 300 #<our-uuid>` in a shell because in that
    # case bash (default shell on some systems) does `execve` without cloning
    # itself - that means there will be no process with commandline like:
    # '/bin/sh -c sleep 300 && true #<our-uuid>' - instead that process would
    # get substituted with 'sleep 300' and the marked commandline would be
    # overwritten.
    # Injecting some flow control (`&&`) forces bash to fork properly.
    marked_command = 'sleep 300 && true #%s' % mark
    executor = SimpleExecutor(marked_command, shell=True)
    executor.start()
    assert executor.running() is True
    assert mark in ps_aux(), "The test process should be running."
    del executor
    gc.collect()  # to force 'del' immediate effect
    assert (mark not in ps_aux(),
            "The test process should not be running at this point.")
开发者ID:jotes,项目名称:mirakuru,代码行数:25,代码来源:test_executor.py


示例3: test_stderr_callback

def test_stderr_callback():
    read_stdout = mock.Mock()
    read_stderr = mock.Mock()
    executor = SimpleExecutor(['bash', '-c', 'echo hello >&2'],
                              stdout_callback=read_stdout,
                              stderr_callback=read_stderr,
                              timeout=2.0)
    executor.start()
    assert read_stdout.call_args_list == []
    assert read_stderr.call_args_list == [mock.call('hello\n')]
开发者ID:spinus,项目名称:mirakuru,代码行数:10,代码来源:test_executor.py


示例4: test_executor_methods_returning_self

def test_executor_methods_returning_self():
    """Test if SimpleExecutor lets to chain start, stop and kill methods."""
    executor = SimpleExecutor(SLEEP_300).start().stop().kill().stop()
    assert not executor.running()

    # Check if context manager returns executor to use it in 'as' phrase:
    with SimpleExecutor(SLEEP_300) as executor:
        assert executor.running()

    with SimpleExecutor(SLEEP_300).start().stopped() as executor:
        assert not executor.running()

    assert SimpleExecutor(SLEEP_300).start().stop().output
开发者ID:ClearcodeHQ,项目名称:mirakuru,代码行数:13,代码来源:test_executor.py


示例5: test_kill_custom_signal_kill

def test_kill_custom_signal_kill():
    """Start process and shuts it down using signal SIGQUIT passed to kill."""
    executor = SimpleExecutor(sleep_300)
    executor.start()
    assert executor.running() is True
    executor.kill(sig=signal.SIGQUIT)
    assert executor.running() is False
开发者ID:jotes,项目名称:mirakuru,代码行数:7,代码来源:test_executor.py


示例6: test_custom_signal_stop

def test_custom_signal_stop():
    """Start process and shuts it down using signal SIGQUIT."""
    executor = SimpleExecutor(sleep_300, sig_stop=signal.SIGQUIT)
    executor.start()
    assert executor.running() is True
    executor.stop()
    assert executor.running() is False
开发者ID:jotes,项目名称:mirakuru,代码行数:7,代码来源:test_executor.py


示例7: test_stop_custom_signal_stop

def test_stop_custom_signal_stop():
    """Start process and shuts it down using signal SIGQUIT passed to stop."""
    executor = SimpleExecutor(SLEEP_300)
    executor.start()
    assert executor.running() is True
    executor.stop(sig=signal.SIGQUIT)
    assert executor.running() is False
开发者ID:ClearcodeHQ,项目名称:mirakuru,代码行数:7,代码来源:test_executor.py


示例8: test_stopping_not_yet_running_executor

def test_stopping_not_yet_running_executor():
    """
    Test if SimpleExecutor can be stopped even it was never running.

    We must make sure that it's possible to call .stop() and SimpleExecutor
    will not raise any exception and .start() can be called afterwards.
    """
    executor = SimpleExecutor(sleep_300)
    executor.stop()
    executor.start()
    assert executor.running() is True
    executor.stop()
开发者ID:jotes,项目名称:mirakuru,代码行数:12,代码来源:test_executor.py


示例9: test_process_output_shell

def test_process_output_shell(command):
    """Start process, check output and shut it down with shell set to True."""
    executor = SimpleExecutor(command, shell=True)
    executor.start()

    assert executor.output().read() == 'foobar'
    executor.stop()
开发者ID:jotes,项目名称:mirakuru,代码行数:7,代码来源:test_executor.py


示例10: test_process_output

def test_process_output(command):
    """Start process, check output and shut it down."""
    executor = SimpleExecutor(command)
    executor.start()

    assert executor.output().read() == 'foobar'
    executor.stop()
开发者ID:jotes,项目名称:mirakuru,代码行数:7,代码来源:test_executor.py


示例11: test_running_process

def test_running_process(command):
    """Start process and shuts it down."""
    executor = SimpleExecutor(command)
    executor.start()
    assert executor.running() is True
    executor.stop()
    assert executor.running() is False

    # check proper __str__ and __repr__ rendering:
    assert 'SimpleExecutor' in repr(executor)
    assert 'sleep 300' in str(executor)
开发者ID:jotes,项目名称:mirakuru,代码行数:11,代码来源:test_executor.py


示例12: test_context_stopped

def test_context_stopped():
    """Start for context, and shuts it for nested context."""
    executor = SimpleExecutor(sleep_300)
    with executor:
        assert executor.running() is True
        with executor.stopped():
            assert executor.running() is False
        assert executor.running() is True

    assert executor.running() is False
开发者ID:jotes,项目名称:mirakuru,代码行数:10,代码来源:test_executor.py


示例13: test_daemons_killing

def test_daemons_killing():
    """
    Test if all subprocesses of SimpleExecutor can be killed.

    The most problematic subprocesses are daemons or other services that
    change the process group ID. This test verifies that daemon process
    is killed after executor's kill().
    """
    executor = SimpleExecutor(('python', sample_daemon_path), shell=True)
    executor.start()
    time.sleep(1)
    assert executor.running() is not True, \
        "Executor should not have subprocess running as it's started daemon."

    assert sample_daemon_path in ps_aux()
    executor.kill()
    assert sample_daemon_path not in ps_aux()

    # Second part of this test verifies exceptions being called if `ps xe -ww`
    # was called on some OS that doesn't have it.
    executor.start()
    time.sleep(1)

    def fake_output(args):
        check_output('something_not_existing_called')

    with mock.patch('subprocess.check_output', side_effect=fake_output) as co:
        with mock.patch('mirakuru.base.log') as log:
            executor.kill()

    assert co.mock_calls == [mock.call(('ps', 'xe', '-ww'))]
    assert 'error' == log.mock_calls[0][0]
    assert '`$ ps xe -ww` command was called' in log.mock_calls[0][1][0]

    assert sample_daemon_path in ps_aux()
    executor.kill()
    assert sample_daemon_path not in ps_aux()
开发者ID:jotes,项目名称:mirakuru,代码行数:37,代码来源:test_executor.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python clock.clock函数代码示例发布时间:2022-05-27
下一篇:
Python runtime.find函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap