How to use the filelock.Timeout function in filelock

To help you get started, we’ve selected a few filelock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mechboxes / mech / mech / utils.py View on Github external
del instances[k]
                        updated = True
            else:
                instances = {}
            instance_data = instances.get(instance_name)
            if not instance_data or force:
                if obj:
                    instance_data = instances[instance_name] = obj
                    updated = True
                else:
                    instance_data = {}
            if updated:
                with open(index_path, 'w') as fp:
                    json.dump(instances, fp, sort_keys=True, indent=2, separators=(',', ': '))
            return instance_data
    except Timeout:
        puts_err(colored.red(textwrap.fill("Couldn't access index, it seems locked.")))
        sys.exit(1)
github raiden-network / raiden / raiden / ui / cli.py View on Github external
sys.exit(ReturnCode.GENERIC_COMMUNICATION_ERROR)
    except EthNodeInterfaceError as e:
        click.secho(str(e), fg="red")
        sys.exit(ReturnCode.ETH_INTERFACE_ERROR)
    except RaidenUnrecoverableError as ex:
        click.secho(f"FATAL: An un-recoverable error happen, Raiden is bailing {ex}", fg="red")
        write_stack_trace(ex)
        sys.exit(ReturnCode.FATAL)
    except APIServerPortInUseError as ex:
        click.secho(
            f"ERROR: API Address {ex} is in use. Use --api-address  "
            f"to specify a different port.",
            fg="red",
        )
        sys.exit(ReturnCode.PORT_ALREADY_IN_USE)
    except filelock.Timeout:
        name_or_id = ID_TO_NETWORKNAME.get(kwargs["network_id"], kwargs["network_id"])
        click.secho(
            f"FATAL: Another Raiden instance already running for account "
            f"{to_checksum_address(address)} on network id {name_or_id}",
            fg="red",
        )
        sys.exit(1)
    except Exception as ex:
        write_stack_trace(ex)
        sys.exit(1)
    finally:
        # teardown order is important because of side-effects, both the
        # switch_monitor and profiler could use the tracing api, for the
        # teardown code to work correctly the teardown has to be done in the
        # reverse order of the initialization.
        if switch_monitor is not None:
github JackSlateur / backurne / src / backurne / backurne.py View on Github external
def wrapper(*args, **kwargs):
		try:
			return func(*args, **kwargs)
		except filelock.Timeout as e:
			Log.debug(e)
		except Exception as e:
			Log.warning(f'{e} thrown while running {func.__name__}()')
	return wrapper
github elemental-lf / benji / src / backy2 / locking.py View on Github external
def lock(self, name):
        """
        Lock access to a specific name. Returns True when locking
        was successful or False if this name is already locked.
        """
        self._locks[name] = FileLock('{}/backy_{}.lock'.format(self._lock_dir, name), timeout=0)
        try:
            self._locks[name].acquire()
        except Timeout:
            return False
        else:
            return True
github bvanheu / pytoutv / toutv3 / toutv3 / cache2.py View on Github external
def load(user):
    _logger.debug('Trying to load cache for user "{}"'.format(user))

    try:
        lock = _get_file_lock(user)
    except:
        # no lock, no luck
        _logger.debug('Cannot get cache file lock object: using empty cache')
        return _Cache(user)

    # acquire cache lock
    try:
        # wait one second until timeout...
        lock.acquire(1)
    except filelock.Timeout:
        # cache is already locked: return empty cache (will not be saved)
        _logger.warn('Cache is locked by lock file "{}": using empty cache'.format(lock.lock_file))
        return _Cache(user)
    except Exception as e:
        # other exception: return empty cache (will not be saved)
        _logger.warn('Cannot acquire lock file "{}": {}'.format(lock.lock_file, e))
        return _Cache(user)

    _logger.debug('Cache lock file "{}" acquired'.format(lock.lock_file))

    try:
        cache_file_name = get_cache_file_name(user)
    except:
        # no lock, no luck
        _logger.debug('Cannot get cache file name: using empty cache')
        lock.release(force=True)
github tox-dev / tox / src / tox / util / lock.py View on Github external
def hold_lock(lock_file, reporter=verbosity1):
    py.path.local(lock_file.dirname).ensure(dir=1)
    lock = FileLock(str(lock_file))
    try:
        try:
            lock.acquire(0.0001)
        except Timeout:
            reporter("lock file {} present, will block until released".format(lock_file))
            lock.acquire()
        yield
    finally:
        lock.release(force=True)
github oracle / opengrok / opengrok-tools / src / main / python / opengrok_tools / mirror.py View on Github external
for x in projects:
                    worker_args.append([x, logdir, args.loglevel,
                                        args.backupcount, config,
                                        args.check_changes,
                                        args.uri, source_root,
                                        args.batch])
                try:
                    project_results = pool.map(worker, worker_args, 1)
                except KeyboardInterrupt:
                    return FAILURE_EXITVAL
                else:
                    if any([x == FAILURE_EXITVAL for x in project_results]):
                        ret = FAILURE_EXITVAL
                    if all([x == CONTINUE_EXITVAL for x in project_results]):
                        ret = CONTINUE_EXITVAL
    except Timeout:
        logger.warning("Already running, exiting.")
        return FAILURE_EXITVAL

    logging.shutdown()
    return ret
github WeblateOrg / weblate / weblate / trans / views / git.py View on Github external
def execute_locked(request, obj, message, call, *args, **kwargs):
    """Helper function to catch possible lock exception."""
    try:
        result = call(*args, **kwargs)
        # With False the call is supposed to show errors on its own
        if result is None or result:
            messages.success(request, message)
    except Timeout as error:
        messages.error(
            request,
            _('Failed to lock the repository, another operation is in progress.')
        )
        report_error(error, request)

    return redirect_param(obj, '#repository')
github DDNStorage / LustrePerfMon / pyesmon / esmon_virt.py View on Github external
def esmon_virt(workspace, config_fpath):
    """
    Start to install virtual machines
    """
    # pylint: disable=bare-except
    lock_file = config_fpath + ".lock"
    lock = filelock.FileLock(lock_file)
    try:
        with lock.acquire(timeout=0):
            try:
                ret = esmon_virt_locked(workspace, config_fpath)
            except:
                ret = -1
                logging.error("exception: %s", traceback.format_exc())
            lock.release()
    except filelock.Timeout:
        ret = -1
        logging.error("someone else is holding lock of file [%s], aborting "
                      "to prevent conflicts", lock_file)
    return ret
github XiaoMi / mace / tools / sh_commands.py View on Github external
def is_device_locked(serialno):
    import filelock
    try:
        with device_lock(serialno, timeout=0.000001):
            return False
    except filelock.Timeout:
        return True

filelock

A platform independent file lock.

Unlicense
Latest version published 3 months ago

Package Health Score

94 / 100
Full package analysis