Fastrlock is a C-level implementation of a re-entrant, optimistic lock for CPython, serving as a drop-in replacement for `threading.RLock`. Implemented in Cython, it offers both a Python and a C-API, designed to optimize for non-congested locking scenarios. It is actively maintained with periodic updates to support newer Python versions, with its current version being 0.8.3.
pip install fastrlockVerified import paths — ran on the pinned version, not inferred.
Initialize and use `fastrlock.rlock()` as a direct replacement for `threading.RLock`. It supports the context manager protocol (`with lock:`).
Benchmark your specific use case if performance is critical. Consider using the Cython C-API for maximum performance benefits if integrating with other Cython modules.
Upgrade to Python 3.7+ and use a recent version of `fastrlock` for official support and continued updates.
Ensure you are using `fastrlock` version 0.7 or later when developing for Python 3.7 and above.
If integrating with Cython code, leverage `from fastrlock cimport rlock` for optimal performance. Otherwise, carefully consider if the Python API provides sufficient benefits for your specific workload.
Install the 'Desktop development with C++' workload, including the 'MSVC v143 - VS 2022 C++ x64/x86 build tools' (or equivalent for your Visual Studio version) from the Visual Studio Installer, or download the Microsoft Visual C++ Build Tools separately from the official Visual Studio website.
Ensure fastrlock is correctly installed by running `pip install fastrlock`. If using a virtual environment, ensure it's activated, and the installation is successful.
Import the correct class as `from fastrlock import FastRLock` to use the class directly, or `from fastrlock import rlock` if you're importing the module-level instance, and then use `FastRLock()` or `rlock` respectively.
To create a lock, you need to instantiate the `FastRLock` class. The correct way is `from fastrlock import FastRLock; lock = FastRLock()` or `import fastrlock; lock = fastrlock.FastRLock()`.