MCPcopy Create free account
hub / github.com/catboost/catboost / test_pidfilelock

Function test_pidfilelock

library/python/filelock/ut/test_filelock.py:85–109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

83
84
85def test_pidfilelock():
86 lock_file = 'pidfile.lock'
87 # there should be no info
88 lock = library.python.filelock.PidFileLock(lock_file)
89 assert lock.info.pid == 0
90 assert lock.info.time == 0
91
92 with library.python.filelock.PidFileLock(lock_file) as lock:
93 assert lock.info.pid == os.getpid()
94 assert lock.info.time <= time.time()
95 assert lock.info.time > time.time() - 2
96
97 newlock = library.python.filelock.PidFileLock(lock_file)
98 # info shouldn't require locking
99 assert newlock.info.pid == os.getpid()
100 assert not newlock.acquire(blocking=False)
101
102 newlock = library.python.filelock.PidFileLock(lock_file)
103 # info is still accessible
104 assert newlock.info.pid == os.getpid()
105 t = newlock.info.time
106 # info is updated
107 time.sleep(1)
108 with newlock as lock:
109 assert lock.info.time > t
110
111
112def _try_acquire_pidlock(lock_file, out_file, lock_pid=None):

Callers

nothing calls this directly

Calls 2

sleepMethod · 0.80
acquireMethod · 0.45

Tested by

no test coverage detected