Skip to main content

RwLock: Reader-Writer lock

Project description

Python Version Pypi Version Code size in bytes

Coverage

License

RwLock: Reader-Writer lock

Introduction

We can simply protect a shared resource by a lock. But the performance is not good because each reader should run one-by-one.

A Reader-Writer lock can improve the performance by let readers running simultaneously.

By the way, a writer should wait until all readers done. In a frequently read situation, a new reader after the writer can also increase the read count, let read count never decrease to 0. This will starve writer.

RwLock:

  1. Let readers running simultaneously.
  2. Exclude "multiple readers" and each writer.
  3. provide a flag "write_first" to prevent starve writer.

After 1.6.0, RwLock can support multi-thread(default) and multi-process. For multi-process scenario, use rwlock = RwLock(cross_process=True)

Usage

Install

  1. pip install cy_rwlock
  2. download latest version from https://pypi.org/project/cy_rwlock/#files

Example


from rwlock import RwLock

rwlock = RwLock()

### READER
rwlock.acquire_r()
# read...
rwlock.release_r()

# OR
with rwlock.lock_r():
    # read...

### WRITER
rwlock.acquire_w()
# write...
rwlock.release_w()

# OR
with rwlock.lock_w():
    # write...

Unittest

  • local(windows)
    • run scripts\run.bat
  • github
    • auto run when push

Deploy

  • PyPI version
    • convertd from git tag
  • local(windows)
    • run scripts\deploy.bat
  • github -> PyPI
    • When release in github

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cy_rwlock-1.7.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cy_rwlock-1.7.2.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

cy_rwlock-1.7.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file cy_rwlock-1.7.2.tar.gz.

File metadata

  • Download URL: cy_rwlock-1.7.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.0

File hashes

Hashes for cy_rwlock-1.7.2.tar.gz
Algorithm Hash digest
SHA256 08680501e3510bfecf3827d86b052f3bdf85a755b7f4c0e94db2c4c2e9a0355b
MD5 df7c9db45e301531c0ff52bf09ee0ef3
BLAKE2b-256 cd2617a6926095dcdf72825963ec2a23b093cf67d470b5ecfd1477622a1ad944

See more details on using hashes here.

File details

Details for the file cy_rwlock-1.7.2.0-py3-none-any.whl.

File metadata

  • Download URL: cy_rwlock-1.7.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for cy_rwlock-1.7.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a5aafe6e6c176b3b3c364179513d1f292ef45c09eb8d84549230254240c65075
MD5 d74fd115347699ff56c8969638742135
BLAKE2b-256 bdb10393e7eb11f9b3f240374fed787f6edfebf9903fd426d884f4ab03bc1172

See more details on using hashes here.

File details

Details for the file cy_rwlock-1.7.2-py3-none-any.whl.

File metadata

  • Download URL: cy_rwlock-1.7.2-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.0

File hashes

Hashes for cy_rwlock-1.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 77679e69c10684ce0a4dc15bde9f46203ebd554124d03462a08596b6044db35c
MD5 31311089e6db91667b5534a7874a1e3f
BLAKE2b-256 4f769b7b1645b67fd17fcc3bd42d87f90979c9d25e3c1e481643951843f3813e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page