skillfed

fastrlock

Fast, re-entrant optimistic lock implemented in Cython

fastrlock v0.8.3 1.2M downloads/30d#4,201 on PyPI36
Permissive license MIT style DORMANT released

What it is and what it does

FastRLock is a Cython-implemented re-entrant lock that serves as a drop-in replacement for threading.RLock. It optimizes for the common case where only one thread holds the lock by avoiding actual lock acquisition until a second thread contends for it, exploiting the GIL to make ownership checks atomic without system-level synchronization overhead.

The package provides both a Python API (compatible with threading.RLock) and a direct Cython C-API for use from other Cython modules. Benchmarks show it can be faster than stdlib RLock in single-threaded scenarios and under light contention, though performance relative to modern Python 3.4+ stdlib implementations varies by CPython version and optimization level. The Cython interface consistently outperforms the Python API by avoiding call overhead.

Use it for:

  • Replace threading.RLock in latency-sensitive single-threaded or lightly-contended code paths where lock overhead matters.
  • Use the Cython C-API from other Cython extensions to avoid Python call overhead in critical sections.
  • Embed in libraries like Lupa that require fast, re-entrant synchronization primitives across multiple threads.
  • Benchmark-driven optimization where profiling shows threading.RLock as a bottleneck in acquire/release-heavy workloads.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

A C-level re-entrant lock for CPython that replaces threading.RLock with faster acquire/release cycles through optimistic locking and Cython implementation.

Yes, if you are optimizing a Cython codebase or have profiled threading.RLock as a bottleneck and target Python versions where it remains faster than stdlib. No, if you are on Python 3.4+ and using only the Python API—stdlib RLock is likely as fast or faster. The Cython API is the strongest use case. Install friction is moderate due to compilation, but wheels cover most platforms.

Install

fastrlock on PyPI

pip

pip install fastrlock

uv

uv add fastrlock

poetry

poetry add fastrlock

Installing fastrlock

Before you install

Medium install friction due to compiled C extensions requiring platform-specific wheels. The package maintains broad wheel coverage across Python 2.7 through 3.11+ and multiple architectures (x86_64, i686, aarch64, arm64, Windows). Last release was 605 days ago; repository is not archived and remains active.

License in practice

MIT-style permissive license allows commercial and private use with minimal restrictions, typical for low-friction adoption in production systems.

Quickstart

from fastrlock import rlock

lock = rlock()
with lock:
    # critical section
    pass

Requires a C compiler and Python development headers at install time; pre-built wheels available for common platforms but source builds may fail without build tools.

Verify before relying

  • Whether performance gains over threading.RLock remain significant in Python 3.4+ versions where stdlib RLock was substantially optimized.
  • Current test coverage and whether the package is actively maintained beyond wheel rebuilds for new Python versions.
  • Compatibility guarantees with CPython implementations other than CPython (PyPy, etc.).

Package facts

License MIT style (permissive)
Python support not specified
Install friction medium — platform-specific wheel
Runtime dependencies none
Maintenance dormant — 605 days since the last release
Last repo commit
First released
Downloads 1,221,732/month — #4,201 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: fastrlock-0.8.3-cp27-cp27m-manylinux_2_5_i686.manylinux1_i686.whl; fastrlock-0.8.3-cp27-cp27m-manylinux_2_5_x86_64.manylinux1_x86_64.whl; fastrlock-0.8.3-cp27-cp27mu-manylinux_2_5_i686.manylinux1_i686.whl; fastrlock-0.8.3-cp27-cp27mu-manylinux_2_5_x86_64.manylinux1_x86_64.whl; fastrlock-0.8.3-cp310-cp310-macosx_11_0_universal2.whl; fastrlock-0.8.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl; fastrlock-0.8.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_24_i686.whl; fastrlock-0.8.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_24_x86_64.whl; fastrlock-0.8.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl; fastrlock-0.8.3-cp310-cp310-musllinux_1_1_aarch64.whl; fastrlock-0.8.3-cp310-cp310-musllinux_1_1_x86_64.whl; fastrlock-0.8.3-cp310-cp310-win_amd64.whl; fastrlock-0.8.3-cp311-cp311-macosx_11_0_universal2.whl; fastrlock-0.8.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl; fastrlock-0.8.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_24_i686.whl; fastrlock-0.8.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_24_x86_64.whl; fastrlock-0.8.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl; fastrlock-0.8.3-cp311-cp311-musllinux_1_1_aarch64.whl; fastrlock-0.8.3-cp311-cp311-musllinux_1_1_x86_64.whl; fastrlock-0.8.3-cp311-cp311-win_amd64.whl

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Information TechnologyLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: CythonProgramming Language :: Python :: 3Topic :: Software Development

Tags

fast reentrant lockthreading rlock replacementcython lock implementationoptimistic locking pythonhigh-performance mutexthread synchronizationconcurrent access control
concurrencycython-extensionperformance-critical

More Software Development packages