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


Python pid.PidFile方法代码示例

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


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

示例1: test_pid_check_samepid_with_blocks

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def test_pid_check_samepid_with_blocks():
    def check_samepid_with_blocks_separate_objects():
        with pid.PidFile(allow_samepid=True):
            with pid.PidFile(allow_samepid=True):
                pass

    def check_samepid_with_blocks_same_objects():
        pidfile = pid.PidFile(allow_samepid=True)
        with pidfile:
            with pidfile:
                pass

        assert not os.path.exists(pidfile.filename)

    if sys.platform != "win32":
        check_samepid_with_blocks_separate_objects()
    else:
        with raising(pid.PidFileConfigurationError):
            check_samepid_with_blocks_separate_objects()

    if sys.platform != "win32":
        check_samepid_with_blocks_same_objects()
    else:
        with raising(pid.PidFileConfigurationError):
            check_samepid_with_blocks_same_objects() 
开发者ID:trbs,项目名称:pid,代码行数:27,代码来源:test_pid.py

示例2: test_pid_check_samepid

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def test_pid_check_samepid():
    def check_samepid():
        pidfile = pid.PidFile(allow_samepid=True)

        try:
            pidfile.create()
            pidfile.create()
        finally:
            pidfile.close()

        assert not os.path.exists(pidfile.filename)

    if sys.platform != "win32":
        check_samepid()
    else:
        with raising(pid.PidFileConfigurationError):
            check_samepid() 
开发者ID:trbs,项目名称:pid,代码行数:19,代码来源:test_pid.py

示例3: test_pid_raises_already_running_when_samepid_and_two_different_pids

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def test_pid_raises_already_running_when_samepid_and_two_different_pids(mock_getpid, mock_kill):
    pidfile_proc1 = pid.PidFile()
    pidfile_proc2 = pid.PidFile(allow_samepid=True)

    try:
        mock_getpid.return_value = 1
        pidfile_proc1.create()

        mock_getpid.return_value = 2
        with raising(pid.PidFileAlreadyRunningError):
            pidfile_proc2.create()

    finally:
        pidfile_proc1.close()
        pidfile_proc2.close()

    assert not os.path.exists(pidfile_proc1.filename)
    assert not os.path.exists(pidfile_proc2.filename) 
开发者ID:trbs,项目名称:pid,代码行数:20,代码来源:test_pid.py

示例4: test_pid_custom_term_signal

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def test_pid_custom_term_signal():
    def _noop(*args, **kwargs):
        pass

    signal.signal(signal.SIGTERM, _noop)

    with pid.PidFile() as pidfile:
        assert signal.getsignal(signal.SIGTERM) == _noop

    assert not os.path.exists(pidfile.filename)


# def test_pid_unknown_term_signal():
#     # Not sure how to properly test this when signal.getsignal returns None
#     #  - perhaps by writing a C extension which might get ugly
#     #
#     with pid.PidFile():
#         assert signal.getsignal(signal.SIGTERM) == None 
开发者ID:trbs,项目名称:pid,代码行数:20,代码来源:test_pid.py

示例5: test_double_close_race_condition

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def test_double_close_race_condition():
    # https://github.com/trbs/pid/issues/22
    pidfile1 = pid.PidFile()
    pidfile2 = pid.PidFile()

    try:
        pidfile1.create()
        assert os.path.exists(pidfile1.filename)
    finally:
        pidfile1.close()
        assert not os.path.exists(pidfile1.filename)

    try:
        pidfile2.create()
        assert os.path.exists(pidfile2.filename)

        # simulate calling atexit in process of pidfile1
        pidfile1.close()

        assert os.path.exists(pidfile2.filename)
    finally:
        pidfile2.close()

    assert not os.path.exists(pidfile1.filename)
    assert not os.path.exists(pidfile2.filename) 
开发者ID:trbs,项目名称:pid,代码行数:27,代码来源:test_pid.py

示例6: _make_lock

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def _make_lock(self):
        directory, filename = os.path.split(self._path)
        return PidFile(filename,
                       directory,
                       register_term_signal_handler=False,
                       register_atexit=False) 
开发者ID:torfsen,项目名称:service,代码行数:8,代码来源:__init__.py

示例7: test_pid_class

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def test_pid_class():
    pidfile = pid.PidFile()
    pidfile.create()
    pidfile.close()
    assert not os.path.exists(pidfile.filename) 
开发者ID:trbs,项目名称:pid,代码行数:7,代码来源:test_pid.py

示例8: test_pid_context_manager

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def test_pid_context_manager():
    with pid.PidFile() as pidfile:
        pass

    assert not os.path.exists(pidfile.filename) 
开发者ID:trbs,项目名称:pid,代码行数:7,代码来源:test_pid.py

示例9: test_pid_pid

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def test_pid_pid():
    with pid.PidFile() as pidfile:
        pidnr = int(open(pidfile.filename, "r").readline().strip())
        assert pidnr == os.getpid(), "%s != %s" % (pidnr, os.getpid())
    assert not os.path.exists(pidfile.filename) 
开发者ID:trbs,项目名称:pid,代码行数:7,代码来源:test_pid.py

示例10: test_pid_pid_win32

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def test_pid_pid_win32():
    def read_pidfile_data():
        return open(pidfile.filename, "r").readline().strip()

    with pid.PidFile() as pidfile:
        # On windows Python2 opens a file but reads an empty line from it
        # Python3 throws IOError(13, Access denied) instead, which we are catching with raising_windows_io_error()
        if sys.version_info.major < 3:
            pidtext = read_pidfile_data()
            assert pidtext == "", "Read '%s' from locked file on Windows with Python2" % (pidtext)
        else:
            with raising_windows_io_error():
                pidtext = read_pidfile_data()
    assert not os.path.exists(pidfile.filename) 
开发者ID:trbs,项目名称:pid,代码行数:16,代码来源:test_pid.py

示例11: test_pid_custom_name

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def test_pid_custom_name():
    with pid.PidFile(pidname="testpidfile") as pidfile:
        pass
    assert not os.path.exists(pidfile.filename) 
开发者ID:trbs,项目名称:pid,代码行数:6,代码来源:test_pid.py

示例12: test_pid_force_tmpdir

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def test_pid_force_tmpdir():
    with pid.PidFile(force_tmpdir=True) as pidfile:
        pass
    assert not os.path.exists(pidfile.filename) 
开发者ID:trbs,项目名称:pid,代码行数:6,代码来源:test_pid.py

示例13: test_pid_custom_dir

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def test_pid_custom_dir():
    with pid.PidFile(piddir=os.path.join(pid.DEFAULT_PID_DIR, "testpidfile.dir")) as pidfile:
        pass
    assert not os.path.exists(pidfile.filename) 
开发者ID:trbs,项目名称:pid,代码行数:6,代码来源:test_pid.py

示例14: test_pid_piddir_exists_as_file

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def test_pid_piddir_exists_as_file():
    with tempfile.NamedTemporaryFile() as tmpfile:
        with raising(IOError):
            with pid.PidFile(piddir=tmpfile.name):
                pass 
开发者ID:trbs,项目名称:pid,代码行数:7,代码来源:test_pid.py

示例15: test_pid_no_term_signal

# 需要导入模块: import pid [as 别名]
# 或者: from pid import PidFile [as 别名]
def test_pid_no_term_signal():
    def _noop(*args, **kwargs):
        pass

    signal.signal(signal.SIGTERM, _noop)
    with pid.PidFile(register_term_signal_handler=False) as pidfile:
        assert signal.getsignal(signal.SIGTERM) is _noop
    assert not os.path.exists(pidfile.filename) 
开发者ID:trbs,项目名称:pid,代码行数:10,代码来源:test_pid.py


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