(lock)
return __inner
Check if lock directory exists before calling function
Check if lock directory exists before calling function
Check if lock directory exists before calling function
def check_lock(lock):
    """
    Check if lock directory exists before calling function
    """

    def __inner(func):

        def __wrapper(*args, **kwargs):

            if os.path.isdir(lock):
                logger.warning('Lock directory detected, function is already running')
                sys.exit()

            # Try to run function
            try:
                # Make the lock directory
                os.makedirs(lock, exist_ok=True)
                out = func(*args, **kwargs)
            except Exception as exc:
                logger.error(exc)
                out = None
            finally:
                # Clean the locks.
                os.rmdir(lock)

            # Return function output
            return out

        return __wrapper

    return __inner
def check_lock ( lock ) : def __inner ( func ) : def __wrapper ( * args , * * kwargs ) : if os . path . isdir ( lock ) : logger . warning ( 'Lock directory detected, function is already running' ) sys . exit ( ) # Try to run function try : # Make the lock directory os . makedirs ( lock , exist_ok = True ) out = func ( * args , * * kwargs ) except Exception as exc : logger . error ( exc ) out = None finally : # Clean the locks. os . rmdir ( lock ) # Return function output return out return __wrapper return __inner