-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
31 lines (21 loc) · 709 Bytes
/
test.py
File metadata and controls
31 lines (21 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import logging
import signal
import sys
import time
from openlock import FileLock, Timeout, set_defaults # noqa: F401
logging.basicConfig(format="%(asctime)s:%(levelname)s:%(name)s:%(process)s:%(message)s")
logger = logging.getLogger("openlock")
logger.setLevel(logging.DEBUG)
def cleanup(signum, frame):
sys.exit()
signal.signal(signal.SIGTERM, cleanup)
signal.signal(signal.SIGINT, cleanup)
if __name__ == "__main__":
try:
with FileLock("test.lock", timeout=0) as L:
logger.debug(f"{L} locked by PID={L.getpid()}")
assert L.locked()
logger.info("Sleeping 20 seconds")
time.sleep(20)
except Timeout as e:
logger.debug(e)