2020-02-06 19:00:41 +01:00

20 lines
437 B
Python

# -*- coding: utf-8 -*-
import fcntl
from contextlib import contextmanager
def locked_ex(lock_file):
def decorator(target):
def wrapper(*args, **kwargs):
with lock_ex(lock_file):
return target(*args, **kwargs)
return wrapper
return decorator
@contextmanager
def lock_ex(lock_file):
with open(lock_file, 'w') as lock:
fcntl.lockf(lock, fcntl.LOCK_EX)
yield lock