cthreading
cthreading implements Python 2 Lock, RLock, and Condition in C, speeding up threads synchronization and decreasing cpu usage.
Performance
cthreading eliminates the overhead of threading.RLock and threading.Condition which are implemented in pure Python in Python 2. In particular, threading.Condition is implemented using polling. In Python 3 threading.Condition is implemented without polling; cthreading implements a similar design in C.
$ time python whispers.py -m cthreading
real 0m2.664s
user 0m2.965s
sys 0m0.808s
$ time python3 whispers.py
real 0m9.664s
user 0m8.949s
sys 0m1.812s
$ time python whispers.py
real 0m14.914s
user 0m16.986s
sys 0m12.690s
$ time python whispers.py -m pthreading
real 0m20.169s
user 0m23.062s
sys 0m17.022s
Your application is unlikely to have similar workload; do not expect this improvement.
For more info see https://github.com/nirs/cthreading/wiki/performance.
Usage
Import cthreading before any other module and monkeypatch the thread and threading modules. From this point, threading.Lock, threading.RLock, and threading.Condition are using cthreading.
import cthreading
cthreading.monkeypatch()
Note: cthreading will raise RuntimeError if the threading module was imported before cthreading.monkeypatch() is called.
Tested platforms
x86_64
Fedora 22 / Python 2.7.10
RHEL 7.2 / Python 2.7.5
RHEL 7.2 / Python 2.7.10+ (upstream)
RHEL 7.1 / Python 2.7.5
RHEL 6.7 / Python-2.6.6
Ubuntu 14.04 Server / Python 2.7.6
Ubuntu 12.04 Server / Python 2.7.3 (python regression tests not available)
Ubuntu 12.04 / Python 2.6.9 (Travis container)
Ubuntu 12.04 / Python 2.7.9 (Travis container)
POWER8E
RHEL 7.2 / Python 2.7.5
RHEL 7.2 / Python 2.7.10+ (upstream)
Hacking
For rpm based distributions:
yum install python-devel python-test
For deb based distributions:
apt-get install python-dev libpython2.7-testsuite
Installing Python packages:
pip install pytest pytest-timeout yappi==0.93
Building and running the quick tests:
make
Before submitting patches, run the Python regression tests suite:
make regrtest
Check the Makefile for more info.
Similar projects
pthreading - uses pthread_mutex and pthread_cond apis directly via ctypes. This introduces undefined behavior and actually slower and increases cpu usage in most cases compared to the original Python implementation.
Metadata
Release files for cthreading 0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cthreading-0.3.tar.gz | 18.7 kB | Without provenance | Details for cthreading-0.3.tar.gz |
Release files / cthreading-0.3.tar.gz
| Download URL | cthreading-0.3.tar.gz |
|---|---|
| Size | 18.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
37fabab25a02848d59f1a1dfee5bd97d3943534b5a966750572859dd7ea5432f
|
|
BLAKE2b-256 checksum How to use checksums |
401d95a62ac94770eda970494fd2f28ebada34a24a0698ee0d0bd832a3d20eb3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for cthreading 0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.