當前位置: 首頁>>代碼示例>>Python>>正文


Python SimpleExecutor.running方法代碼示例

本文整理匯總了Python中mirakuru.base.SimpleExecutor.running方法的典型用法代碼示例。如果您正苦於以下問題:Python SimpleExecutor.running方法的具體用法?Python SimpleExecutor.running怎麽用?Python SimpleExecutor.running使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mirakuru.base.SimpleExecutor的用法示例。


在下文中一共展示了SimpleExecutor.running方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_kill_custom_signal_kill

# 需要導入模塊: from mirakuru.base import SimpleExecutor [as 別名]
# 或者: from mirakuru.base.SimpleExecutor import running [as 別名]
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,代碼行數:9,代碼來源:test_executor.py

示例2: test_running_context

# 需要導入模塊: from mirakuru.base import SimpleExecutor [as 別名]
# 或者: from mirakuru.base.SimpleExecutor import running [as 別名]
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,代碼行數:9,代碼來源:test_executor.py

示例3: test_stop_custom_signal_stop

# 需要導入模塊: from mirakuru.base import SimpleExecutor [as 別名]
# 或者: from mirakuru.base.SimpleExecutor import running [as 別名]
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,代碼行數:9,代碼來源:test_executor.py

示例4: test_custom_signal_stop

# 需要導入模塊: from mirakuru.base import SimpleExecutor [as 別名]
# 或者: from mirakuru.base.SimpleExecutor import running [as 別名]
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,代碼行數:9,代碼來源:test_executor.py

示例5: test_context_stopped

# 需要導入模塊: from mirakuru.base import SimpleExecutor [as 別名]
# 或者: from mirakuru.base.SimpleExecutor import running [as 別名]
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,代碼行數:12,代碼來源:test_executor.py

示例6: test_running_process

# 需要導入模塊: from mirakuru.base import SimpleExecutor [as 別名]
# 或者: from mirakuru.base.SimpleExecutor import running [as 別名]
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,代碼行數:13,代碼來源:test_executor.py

示例7: test_executor_methods_returning_self

# 需要導入模塊: from mirakuru.base import SimpleExecutor [as 別名]
# 或者: from mirakuru.base.SimpleExecutor import running [as 別名]
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,代碼行數:15,代碼來源:test_executor.py

示例8: test_forgotten_stop

# 需要導入模塊: from mirakuru.base import SimpleExecutor [as 別名]
# 或者: from mirakuru.base.SimpleExecutor import running [as 別名]
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,代碼行數:27,代碼來源:test_executor.py

示例9: test_stopping_not_yet_running_executor

# 需要導入模塊: from mirakuru.base import SimpleExecutor [as 別名]
# 或者: from mirakuru.base.SimpleExecutor import running [as 別名]
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,代碼行數:14,代碼來源:test_executor.py

示例10: test_daemons_killing

# 需要導入模塊: from mirakuru.base import SimpleExecutor [as 別名]
# 或者: from mirakuru.base.SimpleExecutor import running [as 別名]
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,代碼行數:39,代碼來源:test_executor.py


注:本文中的mirakuru.base.SimpleExecutor.running方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。