How to use the fasteners.ReaderWriterLock function in fasteners

To help you get started, we’ve selected a few fasteners 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 openstack / taskflow / taskflow / persistence / backends / impl_memory.py View on Github external
def __init__(self, conf=None):
        super(MemoryBackend, self).__init__(conf)
        self.memory = FakeFilesystem(deep_copy=self._conf.get('deep_copy',
                                                              True))
        self.lock = fasteners.ReaderWriterLock()
github openstack / oslo.concurrency / oslo_concurrency / lockutils.py View on Github external
def get_lock_path(conf):
    """Return the path used for external file-based locks.

    :param conf: Configuration object
    :type conf: oslo_config.cfg.ConfigOpts

    .. versionadded:: 1.8
    """
    _register_opts(conf)
    return conf.oslo_concurrency.lock_path


InterProcessLock = fasteners.InterProcessLock
ReaderWriterLock = fasteners.ReaderWriterLock
"""A reader/writer lock.

.. versionadded:: 0.4
"""


class Semaphores(object):
    """A garbage collected container of semaphores.

    This collection internally uses a weak value dictionary so that when a
    semaphore is no longer in use (by any threads) it will automatically be
    removed from this container by the garbage collector.

    .. versionadded:: 0.3
    """
github openstack / oslo.concurrency / oslo_concurrency / lockutils.py View on Github external
def get_lock_path(conf):
    """Return the path used for external file-based locks.

    :param conf: Configuration object
    :type conf: oslo_config.cfg.ConfigOpts

    .. versionadded:: 1.8
    """
    _register_opts(conf)
    return conf.oslo_concurrency.lock_path


InterProcessLock = fasteners.InterProcessLock
ReaderWriterLock = fasteners.ReaderWriterLock
"""A reader/writer lock.

.. versionadded:: 0.4
"""


class FairLocks(object):
    """A garbage collected container of fair locks.

    With a fair lock, contending lockers will get the lock in the order in
    which they tried to acquire it.

    This collection internally uses a weak value dictionary so that when a
    lock is no longer in use (by any threads) it will automatically be
    removed from this container by the garbage collector.
    """
github openstack / taskflow / taskflow / storage.py View on Github external
def __init__(self, flow_detail, backend=None, scope_fetcher=None):
        self._result_mappings = {}
        self._reverse_mapping = {}
        if backend is None:
            # Err on the likely-hood that most people don't make there
            # objects able to be deepcopyable (resources, locks and such
            # can't be deepcopied)...
            backend = impl_memory.MemoryBackend({'deep_copy': False})
            with contextlib.closing(backend.get_connection()) as conn:
                conn.update_flow_details(flow_detail, ignore_missing=True)
        self._backend = backend
        self._flowdetail = flow_detail
        self._transients = {}
        self._injected_args = {}
        self._lock = fasteners.ReaderWriterLock()
        self._ensure_matchers = [
            ((task.Task,), (models.TaskDetail, 'Task')),
            ((retry.Retry,), (models.RetryDetail, 'Retry')),
        ]
        if scope_fetcher is None:
            scope_fetcher = lambda atom_name: None
        self._scope_fetcher = scope_fetcher

        # NOTE(imelnikov): failure serialization looses information,
        # so we cache failures here, in atom name -> failure mapping.
        self._failures = {}
        for ad in self._flowdetail:
            fail_cache = {}
            if ad.failure is not None:
                fail_cache[states.EXECUTE] = ad.failure
            if ad.revert_failure is not None:
github Mangopay / mangopay2-python-sdk / mangopaysdk / tools / storages / defaultstoragestrategy.py View on Github external
def Get(self, envKey):
        """Gets the currently stored objects as dictionary.
        return stored Token dictionary or null.
        """
        DefaultStorageStrategy.cache_path = os.path.join(Configuration.TempPath, "cached-data." + envKey + ".py")

        if not os.path.exists(DefaultStorageStrategy.cache_path):
           return None
        lock = fasteners.ReaderWriterLock()
        with lock.read_lock():
            fp = open(DefaultStorageStrategy.cache_path,'rb')
            serializedObj = fp.read().decode('UTF-8')
            try:
               cached = json.loads(serializedObj[1:])
            except:
               cached = None
            fp.close()
        return OAuthToken(cached)
github openstack / taskflow / taskflow / persistence / backends / impl_dir.py View on Github external
def __init__(self, conf):
        super(DirBackend, self).__init__(conf)
        max_cache_size = self._conf.get('max_cache_size')
        if max_cache_size is not None:
            max_cache_size = int(max_cache_size)
            if max_cache_size < 1:
                raise ValueError("Maximum cache size must be greater than"
                                 " or equal to one")
            self.file_cache = cachetools.LRUCache(max_cache_size)
        else:
            self.file_cache = {}
        self.encoding = self._conf.get('encoding', self.DEFAULT_FILE_ENCODING)
        if not self._path:
            raise ValueError("Empty path is disallowed")
        self._path = os.path.abspath(self._path)
        self.lock = fasteners.ReaderWriterLock()
github Mangopay / mangopay2-python-sdk / mangopaysdk / tools / storages / defaultstoragestrategy.py View on Github external
def Store(self, obj, envKey):
        """Stores authorization token passed as an argument.
        param obj instance to be stored.
        """
        DefaultStorageStrategy.cache_path = os.path.join(Configuration.TempPath, "cached-data." + envKey + ".py")

        if obj == None:
            return
        lock = fasteners.ReaderWriterLock()
        with lock.write_lock():
            fp = open(DefaultStorageStrategy.cache_path,'w')
            os.chmod(DefaultStorageStrategy.cache_path, stat.S_IRUSR|stat.S_IWUSR)
            # Write it to the result to the file as a json
            serializedObj = "#" + json.dumps(obj.__dict__)
            # add hash to prevent download token file via http when path is invalid
            fp.write(serializedObj)
            fp.close()