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


Python lockfile.LockFile方法代码示例

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


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

示例1: dump

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import LockFile [as 别名]
def dump(self, app_name):
        """Store information in a cache."""
        cache = self._cache(app_name)

        # Attempt to write out our version check file
        with lockfile.LockFile(str(cache)):
            if cache.exists():
                with cache.open() as fp:
                    state = json.load(fp)
            else:
                state = {}

            state[sys.prefix] = attr.asdict(self)

            with cache.open('w') as fp:
                json.dump(state, fp, sort_keys=True) 
开发者ID:SwissDataScienceCenter,项目名称:renku-python,代码行数:18,代码来源:version.py

示例2: _lock_state_file

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import LockFile [as 别名]
def _lock_state_file(self):
        if not self.lock:
            return
        self._lockfile = LockFile(self.path)

        if (self._lockfile.is_locked() and
                (time() - getmtime(self._lockfile.lock_file)) > 10):
            self._lockfile.break_lock()

        self._lockfile.acquire() 
开发者ID:bq,项目名称:web2board,代码行数:12,代码来源:app.py

示例3: _create_unique_file

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import LockFile [as 别名]
def _create_unique_file(temp):
        temp._check_open()
        with lockfile.LockFile(join(temp.dpath, 'tempfile.lock')):
            flag = True
            while flag or exists(temp.fpath):
                temp.fname = six.text_type(uuid.uuid4()) + '.temp'
                temp.fpath = join(temp.dpath, temp.fname)
                flag = False
            ut.touch(temp.fpath, verbose=temp.verbose) 
开发者ID:Erotemic,项目名称:ibeis,代码行数:11,代码来源:pickle_flann.py

示例4: upload

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import LockFile [as 别名]
def upload():
    return lockfile.LockFile(os.path.join(lock_folder, 'upload')) 
开发者ID:l3uddz,项目名称:cloudplow,代码行数:4,代码来源:lock.py

示例5: sync

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import LockFile [as 别名]
def sync():
    return lockfile.LockFile(os.path.join(lock_folder, 'sync')) 
开发者ID:l3uddz,项目名称:cloudplow,代码行数:4,代码来源:lock.py

示例6: hidden

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import LockFile [as 别名]
def hidden():
    return lockfile.LockFile(os.path.join(lock_folder, 'hidden')) 
开发者ID:l3uddz,项目名称:cloudplow,代码行数:4,代码来源:lock.py

示例7: convert_environment

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import LockFile [as 别名]
def convert_environment(datadir, version, always_yes):
    """
    Converts an environment TO the version specified by `version`.
    :param datadir: The datadir to convert.
    :param version: The version to convert TO.
    :param always_yes: True if the user shouldn't be prompted about the migration.
    """
    # Since we don't call either load() or new() we have to call require_images ourselves.
    require_images()

    inp = None
    old_version = _get_current_format(datadir)
    migration_func = migrations[(old_version, version)]

    if version > CURRENT_FORMAT_VERSION:
        raise DatacatsError('Cannot migrate to a version higher than the '
                            'current one.')
    if version < 1:
        raise DatacatsError('Datadir versioning starts at 1.')

    if not always_yes:
        while inp != 'y' and inp != 'n':
            inp = raw_input(migration_func.__doc__.format(version))

        if inp == 'n':
            sys.exit(1)

    lockfile = LockFile(path_join(datadir, '.migration_lock'))
    lockfile.acquire()

    try:
        # FIXME: If we wanted to, we could find a set of conversions which
        # would bring us up to the one we want if there's no direct path.
        # This isn't necessary with just two formats, but it may be useful
        # at 3.
        # Call the appropriate conversion function
        migration_func(datadir)
    finally:
        lockfile.release() 
开发者ID:datacats,项目名称:datacats,代码行数:41,代码来源:migrate.py

示例8: is_locked

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import LockFile [as 别名]
def is_locked(datadir):
    """
    Return True if this datadir is locked for migrations
    """
    lockfile = LockFile(datadir + '/.migration_lock')
    return lockfile.is_locked() 
开发者ID:datacats,项目名称:datacats,代码行数:8,代码来源:migrate.py

示例9: lock_and_write_to_file

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import LockFile [as 别名]
def lock_and_write_to_file(filename, text):
  with LockFile(filename) as lock:
    with open(filename, 'a') as fid:
      fid.write('{}\n'.format(text)) 
开发者ID:yalesong,项目名称:pvse,代码行数:6,代码来源:train.py

示例10: greentea_get_app_sem

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import LockFile [as 别名]
def greentea_get_app_sem():
    """ Obtain locking mechanism info
    """
    greentea_home_dir_init()
    gt_instance_uuid = str(uuid.uuid4())   # String version
    gt_file_sem_name = os.path.join(HOME_DIR, GREENTEA_HOME_DIR, gt_instance_uuid)
    gt_file_sem = lockfile.LockFile(gt_file_sem_name)
    return gt_file_sem, gt_file_sem_name, gt_instance_uuid 
开发者ID:ARMmbed,项目名称:mbed-os-tools,代码行数:10,代码来源:mbed_greentea_dlm.py

示例11: greentea_get_target_lock

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import LockFile [as 别名]
def greentea_get_target_lock(target_id):
    greentea_home_dir_init()
    file_path = os.path.join(HOME_DIR, GREENTEA_HOME_DIR, target_id)
    lock = lockfile.LockFile(file_path)
    return lock 
开发者ID:ARMmbed,项目名称:mbed-os-tools,代码行数:7,代码来源:mbed_greentea_dlm.py

示例12: greentea_get_global_lock

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import LockFile [as 别名]
def greentea_get_global_lock():
    greentea_home_dir_init()
    file_path = os.path.join(HOME_DIR, GREENTEA_HOME_DIR, GREENTEA_GLOBAL_LOCK)
    lock = lockfile.LockFile(file_path)
    return lock 
开发者ID:ARMmbed,项目名称:mbed-os-tools,代码行数:7,代码来源:mbed_greentea_dlm.py

示例13: download_file

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import LockFile [as 别名]
def download_file(
        url,
        local_filepath,
        chunk_size=1024*512,
        lock_timeout=10,
        http_timeout=None,
        session=None
):
    # pylint: disable=too-many-arguments
    """
    A helper function which can download a file from a specified ``url`` to a
    local file ``local_filepath`` in chunks and using a file lock to prevent
    a concurrent download of the same file.
    """
    # Avoid unnecessary dependencies when the function is not used.
    import lockfile
    import requests

    log.debug("Checking file existance in '%s'", local_filepath)
    lock = lockfile.LockFile(local_filepath)
    try:
        lock.acquire(timeout=lock_timeout)
    except lockfile.LockTimeout:
        log.info(
            "File '%s' is locked. Probably another instance is still downloading it.",
            local_filepath
        )
        raise
    try:
        if not os.path.exists(local_filepath):
            log.info("Downloading a file from '%s' to '%s'", url, local_filepath)
            if session is None:
                session = requests
            response = session.get(url, stream=True, timeout=http_timeout)
            if response.status_code != 200:
                log.error("Download '%s' is failed: %s", url, response)
                response.raise_for_status()
            with open(local_filepath, 'wb') as local_file:
                for chunk in response.iter_content(chunk_size=chunk_size):
                    # filter out keep-alive new chunks
                    if chunk:
                        local_file.write(chunk)
        log.debug("File '%s' has been downloaded", local_filepath)
        return local_filepath
    finally:
        lock.release() 
开发者ID:frol,项目名称:flask-restplus-server-example,代码行数:48,代码来源:utils.py

示例14: __init__

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import LockFile [as 别名]
def __init__(self, counter, **kwargs):
        super(PLCDevice, self).__init__(lock_path=kwargs['lockfile'])

        # these are required, so if they are missing from the config
        # dict passed in, we will want the exception to propagate up
        self.device_name = kwargs['device_name']
        self.hardware_type = self._device_hardware.get(kwargs['hardware_type'], DEVICEBUS_UNKNOWN_HARDWARE)

        # these are optional values, so they may not exist in the config.
        # if they do not exist, they will hold a default value
        self.bus_timeout = kwargs.get('timeout', 0.25)
        self.bus_baud = kwargs.get('bps', 115200)
        self.retry_limit = kwargs.get('retry_limit', 3)
        self.time_slice = kwargs.get('time_slice', 75)

        # hold the reference to the app's sequence number generator
        # FIXME - passing the reference around seems weird and could make things
        # uncomfortable later on. instead, one thing to investigate would be to
        # have the counter as part of the root class for devicebus interfaces, that
        # way, all implementations of devicebus interfaces should have access to it
        # and *should* be able to increment it safely, with all other interfaces
        # respecting the incrementation...
        #
        # another potential solution here would be to store the counter in the app
        # config and have the app context be passed to the devicebus interfaces on
        # init, but that isn't too different from this.
        self._count = counter

        self._lock = lockfile.LockFile(self.serial_lock)

        self._command_map = {
            cid.VERSION: self._version,
            cid.SCAN: self._scan,
            cid.SCAN_ALL: self._scan_all,
            cid.READ: self._read,
            cid.POWER: self._power,
            cid.ASSET: self._asset,
            cid.BOOT_TARGET: self._boot_target,
            cid.CHAMBER_LED: self._chamber_led,
            cid.LED: self._led,
            cid.FAN: self._fan,
            cid.HOST_INFO: self._host_info
        }

        # since PLC devices are "dumb", meaning one device talks to a range of board_ids
        # we expose the range here.  for single-board devices, an alternate 'board_id' property is exposed.
        self.board_id_range = kwargs['board_id_range']
        self.board_id_range_max = kwargs['board_id_range_max'] 
开发者ID:vapor-ware,项目名称:OpenDCRE,代码行数:50,代码来源:plc_device.py


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