Exemple #1
0
def acquire_lock():
    logging.debug("acquiring lock...")

    if LOCK_TYPE == 'MkdirLockFile':
        # mkdir(2)() system call as the basic lock mechanism
        lock = MkdirLockFile("send_mail")
    else:
        # Default Lock Type
        lock = FileLock("send_mail")

    try:
        lock.acquire(LOCK_WAIT_TIMEOUT)
    except AlreadyLocked:
        logging.debug("lock already in place. quitting.")
        return False, lock
    except LockTimeout:
        logging.debug("waiting for the lock timed out. quitting.")
        return False, lock
    logging.debug("acquired.")
    return True, lock
Exemple #2
0
 def sync_folder(self, reload_tree=True):
     encrypted_folder_lock = LockFile(self.encrypted_folder)
     if encrypted_folder_lock.is_locked():
         self.info("Acquiring the lock of encrypted folder...")
     else:
         self.debug("Encrypted folder is not locked")
     with encrypted_folder_lock:
         self.debug("Acquired the encrypted folder's lock")
         plain_folder_lock = LockFile(self.plain_folder)
         if plain_folder_lock.is_locked():
             self.info("Acquiring the lock of plaintext folder...")
         else:
             self.debug("Plaintext folder is not locked")
         with plain_folder_lock:
             self.debug("Acquired the plaintext folder's lock")
             if reload_tree:
                 self._load_encrypted_tree()
                 self._load_plain_tree()
                 self._load_snapshot_tree()
             self._do_sync_folder()
 def save(self, save_path, step):
     logger.debug(f"save model to {save_path}")
     with MkdirLockFile(save_path):
         checkpoint_path = os.path.join(save_path,
                                        'model-%s.ckpt' % self.model_name)
         self.saver.save(self.sess,
                         checkpoint_path,
                         global_step=step,
                         write_meta_graph=False)
         self.latest_checkpoint = checkpoint_path
         logger.debug(f"saved model path {checkpoint_path}")
         return checkpoint_path
Exemple #4
0
 def sync_folder(self, reload_tree=True):
     encrypted_folder_lock = LockFile(self.encrypted_folder)
     if encrypted_folder_lock.is_locked():
         self.info("Acquiring the lock of encrypted folder...")
     else:
         self.debug("Encrypted folder is not locked")
     with encrypted_folder_lock:
         self.debug("Acquired the encrypted folder's lock")
         plain_folder_lock = LockFile(self.plain_folder)
         if plain_folder_lock.is_locked():
             self.info("Acquiring the lock of plaintext folder...")
         else:
             self.debug("Plaintext folder is not locked")
         with plain_folder_lock:
             self.debug("Acquired the plaintext folder's lock")
             if reload_tree:
                 self._load_encrypted_tree()
                 self._load_plain_tree()
                 self._load_snapshot_tree()
             if self.snapshot_tree is None:
                 self._load_snapshot_tree()
             self._do_sync_folder()
Exemple #5
0
    def load_play_data(self):
        with MkdirLockFile(self.config.resource.play_data_dir):
            filenames = get_game_data_filenames(self.config.resource)
            updated = False
            for filename in filenames:
                if filename in self.loaded_filenames:
                    continue
                self.load_data_from_file(filename)
                updated = True

            for filename in (self.loaded_filenames - set(filenames)):
                self.unload_data_of_file(filename)
                updated = True

            if updated:
                self.dataset = DataSet(self.loaded_data)
                logger.debug(f"updating training dataset size {self.dataset_size}")