def spawn_watchdog(): """Spawn a new process for watchdog_loop if WATCHDOGLOCK is not locked""" if WATCHDOGLOCK.is_locked(): raise lockfile.AlreadyLocked('Watchdog already runing') watchdog_proc = mp.Process(target=watchdog_loop, args=(TIMEOUT, )) watchdog_proc.start() LOGGER.info(f'Started watchdog process on {watchdog_proc.pid}')
def acquire(self): logging.debug("Locking %s", self.path) try: fcntl.flock(self.lock_file.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) self._has_lock = True except IOError, e: raise lockfile.AlreadyLocked()
def spawn_daemon(): """Spawn a new process for main_loop if DAEMONLOCK is not locked""" if DAEMONLOCK.is_locked(): raise lockfile.AlreadyLocked('Daemon already running') main_proc = mp.Process(target=main_loop) main_proc.start() LOGGER.info(f'Started main process on {main_proc.pid}')
def mock_acquire(timeout=None): if scenario['locking_pid'] is not None: raise lockfile.AlreadyLocked() scenario['locking_pid'] = scenario['pid']