當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。