当前位置: 首页>>代码示例>>Python>>正文


Python fasteners.InterProcessLock方法代码示例

本文整理汇总了Python中fasteners.InterProcessLock方法的典型用法代码示例。如果您正苦于以下问题:Python fasteners.InterProcessLock方法的具体用法?Python fasteners.InterProcessLock怎么用?Python fasteners.InterProcessLock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fasteners的用法示例。


在下文中一共展示了fasteners.InterProcessLock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ensure_setup

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def ensure_setup(root, folders=(), file_templates=(), force=False, **kwargs):
    with fasteners.InterProcessLock(os.path.join(root, FOLDER_LOCKFILE_NAME)):
        created_folders = []
        for path in [root] + [os.path.join(root, p) for p in folders]:
            if not os.path.exists(path):
                os.makedirs(path)
                created_folders.append(path)

        created_files = collections.OrderedDict()
        for relpath, template in collections.OrderedDict(file_templates).items():
            path = os.path.join(root, relpath)
            if force or not os.path.exists(path):
                body = template.format(**kwargs)
                with open(path, 'w') as file:
                    file.write(body)
                created_files[path] = body

    return created_folders, created_files 
开发者ID:bopen,项目名称:elevation,代码行数:20,代码来源:util.py

示例2: _update_db

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def _update_db(self):
        if self._prim_db:
            lock = InterProcessLock("%s.lock" % self._prim_db)
            acquired = lock.acquire(blocking=False)
            if not acquired:
                logger.debug("Waiting 60 seconds for file lock")
                acquired = lock.acquire(blocking=True, timeout=60)
            if acquired:
                try:
                    with open(self._prim_db, "w", encoding="utf-8") as out:
                        out.write(unicode(json.dumps(self._dbs[self._prim_db])))
                    return True
                finally:
                    lock.release()
            else:
                logger.error(
                    "Could not update platform database: "
                    "Lock acquire failed after 60 seconds"
                )
                return False
        else:
            logger.error(
                "Can't update platform database: destination database is ambiguous"
            )
            return False 
开发者ID:ARMmbed,项目名称:mbed-os-tools,代码行数:27,代码来源:platform_database.py

示例3: GetDefaultScheduler

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def GetDefaultScheduler() -> GpuScheduler:
  gpus = GPUtil.getGPUs()
  if not gpus:
    raise NoGpuAvailable("No GPUs available")

  if os.environ.get("TEST_TARGET") and os.environ.get("TEST_WITH_GPU") != "1":
    raise NoGpuAvailable("GPUs disabled for tests")

  app.Log(
    2, "Creating default scheduler for %s", humanize.Plural(len(gpus), "GPU")
  )
  return GpuScheduler(
    {gpu: fasteners.InterProcessLock(_LOCK_DIR / str(gpu.id)) for gpu in gpus}
  )


# This function is memoized since we can always acquire the same lock twice. 
开发者ID:ChrisCummins,项目名称:clgen,代码行数:19,代码来源:gpu_scheduler.py

示例4: lock

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def lock(self):
        if not self.sig_id:
            return
        # we will need to lock on a file that we do not really write to
        # otherwise the lock will be broken when we write to it.
        self._lock = fasteners.InterProcessLock(
            os.path.join(env.temp_dir, self.sig_id + '.lock'))
        if not self._lock.acquire(blocking=False):
            self._lock = None
            raise UnavailableLock((self.input_files, self.output_files,
                                   os.path.join(env.temp_dir,
                                                self.sig_id + '.lock')))
        else:
            env.log_to_file(
                'TARGET',
                f'Lock acquired for output files {short_repr(self.output_files)}'
            ) 
开发者ID:vatlab,项目名称:sos,代码行数:19,代码来源:targets.py

示例5: update_results_thread

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def update_results_thread(filename, info):
    thread_lock.acquire()
    with fasteners.InterProcessLock('{0}.lock'.format(filename)):
        content = json.loads(read(filename))
        name = info['name']
        result = info['result']
        refit_config = info['refit_config']
        text = info['text']
        seed = str(info['seed'])

        infos = content[name] if name in content else dict()
        infos[seed] = {'result': result, 'description': text, 'refit': refit_config}
        content[name] = infos

        write(filename, json.dumps(content, indent=4, sort_keys=True))
    thread_lock.release() 
开发者ID:automl,项目名称:Auto-PyTorch,代码行数:18,代码来源:thread_read_write.py

示例6: _mkdir_threadsafe_unique

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def _mkdir_threadsafe_unique(log_dir_root, log_date, postfix_dir_name):
    os.makedirs(log_dir_root, exist_ok=True)
    # Make sure only one process at a time writes into log_dir_root
    with fasteners.InterProcessLock(os.path.join(log_dir_root, 'lock')):
        return _mkdir_unique(log_dir_root, log_date, postfix_dir_name) 
开发者ID:fab-jul,项目名称:imgcomp-cvpr,代码行数:7,代码来源:logdir_helpers.py

示例7: _write_to_sheets

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def _write_to_sheets(log_date, ae_config_rel_path, pc_config_rel_path,
                     description, git_ref,
                     log_dir_root, is_continue):
    try:
        with fasteners.InterProcessLock(sheets_logger.get_lock_file_p()):
            sheets_logger.insert_row(
                    log_date + ('c' if is_continue else ''),
                    os.environ.get('JOB_ID', 'N/A'),
                    ae_config_rel_path, pc_config_rel_path, description, '',
                    git_ref,
                    log_dir_root)
    except sheets_logger.GoogleSheetsAccessFailedException as e:
        print(e) 
开发者ID:fab-jul,项目名称:imgcomp-cvpr,代码行数:15,代码来源:train.py

示例8: _acquire_lock

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def _acquire_lock(self):
        with fasteners.InterProcessLock(self.lock_file):
            yield 
开发者ID:fab-jul,项目名称:L3C-PyTorch,代码行数:5,代码来源:multiscale_tester.py

示例9: get_lock

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def get_lock():
    lock = fasteners.InterProcessLock(settings.get('worker', 'LOCK_FILE'))
    gotten = lock.acquire(blocking=False, timeout=settings.getfloat('worker', 'LOCK_TIMEOUT_IN_SECS'))
    yield gotten

    if gotten:
        lock.release() 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:9,代码来源:tasks.py

示例10: __init__

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def __init__(self, filename):
        self._file = None
        self._filename = filename
        self._process_lock = fasteners.InterProcessLock(
            '{0}.lock'.format(filename))
        self._thread_lock = threading.Lock()
        self._read_only = False
        self._credentials = {} 
开发者ID:Deltares,项目名称:aqua-monitor,代码行数:10,代码来源:multiprocess_file_storage.py

示例11: storage_file_lock

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def storage_file_lock(storage_file_path):
    with fasteners.InterProcessLock('{0}.lock'.format(storage_file_path)):
        yield 
开发者ID:cloudify-cosmo,项目名称:cloudify-manager,代码行数:5,代码来源:utils.py

示例12: _setup_for_mmap

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def _setup_for_mmap(self):
        # Setup variables for get_vectors_mmap()
        self._all_vectors = None
        self._approx_index = None
        if not self.memory_db:
            self.db_hash = fast_md5_file(self.path)
        else:
            self.db_hash = self.uid
        self.md5 = hashlib.md5(",".join(
            [self.path, self.db_hash, str(self.length),
             str(self.dim), str(self.precision), str(self.case_insensitive)
             ]).encode('utf-8')).hexdigest()
        self.path_to_mmap = os.path.join(tempfile.gettempdir(),
                                         self.md5 + '.magmmap')
        self.path_to_approx_mmap = os.path.join(tempfile.gettempdir(),
                                                self.md5 + '.approx.magmmap')
        if self.path_to_mmap not in Magnitude.MMAP_THREAD_LOCK:
            Magnitude.MMAP_THREAD_LOCK[self.path_to_mmap] = threading.Lock()
        if self.path_to_approx_mmap not in Magnitude.MMAP_THREAD_LOCK:
            Magnitude.MMAP_THREAD_LOCK[self.path_to_approx_mmap] = \
                threading.Lock()
        self.MMAP_THREAD_LOCK = Magnitude.MMAP_THREAD_LOCK[self.path_to_mmap]
        self.MMAP_PROCESS_LOCK = InterProcessLock(self.path_to_mmap + '.lock')
        self.APPROX_MMAP_THREAD_LOCK = \
            Magnitude.MMAP_THREAD_LOCK[self.path_to_approx_mmap]
        self.APPROX_MMAP_PROCESS_LOCK = \
            InterProcessLock(self.path_to_approx_mmap + '.lock')
        self.setup_for_mmap = True 
开发者ID:plasticityai,项目名称:magnitude,代码行数:30,代码来源:__init__.py

示例13: lock

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def lock(self):
        return fasteners.InterProcessLock(self.lock_file_name) 
开发者ID:emc-openstack,项目名称:storops,代码行数:4,代码来源:utils.py

示例14: _concurrent_update

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def _concurrent_update(lock_files, node, key, first_value, second_value, holder_path):
    holder = helpers.FilesystemDataHolder(holder_path)
    locker1 = fasteners.InterProcessLock(lock_files[0])
    locker2 = fasteners.InterProcessLock(lock_files[1])

    first = locker1.acquire(blocking=False)

    if first:
        # Give chance for both processes to acquire locks
        while locker2.acquire(blocking=False):
            locker2.release()
            time.sleep(0.1)
    else:
        locker2.acquire()

    node.attributes[key] = first_value if first else second_value
    holder['key'] = first_value if first else second_value
    holder.setdefault('invocations', 0)
    holder['invocations'] += 1

    if first:
        locker1.release()
    else:
        with locker1:
            locker2.release()

    return first 
开发者ID:apache,项目名称:incubator-ariatosca,代码行数:29,代码来源:test_process_executor_concurrent_modifications.py

示例15: _path_lock

# 需要导入模块: import fasteners [as 别名]
# 或者: from fasteners import InterProcessLock [as 别名]
def _path_lock(self, path):
        lockfile = self._join_path(path, 'lock')
        with fasteners.InterProcessLock(lockfile) as lock:
            with _storagefailure_wrapper():
                yield lock 
开发者ID:openstack,项目名称:taskflow,代码行数:7,代码来源:impl_dir.py


注:本文中的fasteners.InterProcessLock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。