@contextmanager
def pid_lock(lock_file_path):
    lock_dir = os.path.dirname(lock_file_path)
    if not os.path.exists(lock_dir):
        os.makedirs(lock_dir)

    has_lock = False
    try:
        if os.path.isfile(lock_file_path):
            lockfile = open(lock_file_path)
            pid = int(lockfile.readline())
            if pid == os.getpid():
                has_lock = True
            else:
                raise DaemonAlreadyRunningException('Daemon is already running with process id %d' % pid)
        else:
            with open(lock_file_path, 'w') as lock_file:
                pid = os.getpid()
                lock_file.write(str(pid)+'\n')
            has_lock = True
        yield pid
    finally:
        if has_lock:
            os.remove(lock_file_path)
Return a number formatted using scientific notation for the locale.
dataset/ETHPy150Open jumoconnect/openjumo/jumodjango/utils/base_daemon.py/pid_lock--crossover with--dataset/ETHPy150Open cloudera/hue/desktop/core/ext-py/Babel-0.9.6/babel/support.py/Format.scientific