Lightweight cooperative microthreads for Pyhton
Project description
Overview
Fibers are lightweight primitives for cooperative multitasking in Python. They provide means for running pieces of code that can be paused and resumed. Unlike threads, which are preemptively scheduled, fibers are scheduled cooperatively, that is, only one fiber will be running at a given point in time, and no other fiber will run until the user explicitly decides so.
When a fiber is created it will not run automatically. A fiber must be ‘switched’ into for it to run. Fibers can switch control to other fibers by way of the switch or throw functions, which switch control or raise and exception in the target fiber respectively.
Example:
import fibers def func1(): print "1" f2.switch() print "3" f2.switch() def func2(): print "2" f1.switch() print "4" f1 = fibers.Fiber(target=func1) f2 = fibers.Fiber(target=func2) f1.switch()
The avove example will print “1 2 3 4”, but the result was obtained by the cooperative work of 2 fibers yielding control to each other.
CI status
Documentation
Installing
fibers can be installed via pip as follows:
pip install fibers
Building
Get the source:
git clone https://github.com/saghul/python-fibers
Linux:
./build_inplace
Mac OSX:
(XCode needs to be installed) export ARCHFLAGS="-arch x86_64" ./build_inplace
Microsoft Windows:
python setup.py build_ext --inplace
Running the test suite
The test suite can be run using nose:
nosetests -v
License
Unless stated otherwise on-file fibers uses the MIT license, check LICENSE file.
Supported Python versions
Python >= 2.7 and >= 3.3 are supported. Other older Python versions might work, but they are not actively tested. CPython and PyPy are supported.
Supported architectures
x86, x86-64, ARM, MIPS64, PPC64 and s390x are supported.
Contributing
If you’d like to contribute, fork the project, make a patch and send a pull request. Have a look at the surrounding code and please, make yours look alike.
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
Built Distributions
File details
Details for the file fibers-1.1.0.tar.gz
.
File metadata
- Download URL: fibers-1.1.0.tar.gz
- Upload date:
- Size: 36.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 624de9b23547838459765fa2386c31afea414fca34558895e2f867eeacbb4fce |
|
MD5 | 93fee8da8a53bdaa107bb098e576c7f6 |
|
BLAKE2b-256 | 91127b683d9589d3052d3d5366529e60db58f797b4ffd4b1146b86488f736ab0 |
File details
Details for the file fibers-1.1.0-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: fibers-1.1.0-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 16.3 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5416584f3d06144ba25fc2304c7643ce4812b9a4b366fa9271a093d6293e96ee |
|
MD5 | e91ecc187cb205ea0405c97f8b248f4f |
|
BLAKE2b-256 | 183e2e8ed0e30860fba8dfd280d17ea2a977085b705e43224d7c45ea98e5b906 |
File details
Details for the file fibers-1.1.0-cp36-cp36m-win32.whl
.
File metadata
- Download URL: fibers-1.1.0-cp36-cp36m-win32.whl
- Upload date:
- Size: 15.0 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89c099bcc523d1227392f9e8d72fee958d19dbf2003d089af4a7d2b8b03399de |
|
MD5 | 788b36313e1cf8094fbe000ebc9989d9 |
|
BLAKE2b-256 | c848629c16b9af1e9670fa65b16c1adc36f1310106fc4ed1f6e7dadae0408387 |
File details
Details for the file fibers-1.1.0-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: fibers-1.1.0-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 16.3 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 443ee28e8284c1002a76480dfce301be710de1e30df1f6d4a6558ad71d1bf6d5 |
|
MD5 | 2a47324939eb9bc588149a877c56d208 |
|
BLAKE2b-256 | 440ef0bc709341dc3c3b005aa6087397bbbe9e87dcd3d981a9390d4d1ea309de |
File details
Details for the file fibers-1.1.0-cp35-cp35m-win32.whl
.
File metadata
- Download URL: fibers-1.1.0-cp35-cp35m-win32.whl
- Upload date:
- Size: 15.0 kB
- Tags: CPython 3.5m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40f7fac249a7701f1e775db025583b773b401bdb48fa4e1c234497935b336bde |
|
MD5 | a1431677ade2b879e21fab145e8a4b29 |
|
BLAKE2b-256 | bb462958f5a535f29fa9ac53a91663e71e548d46db35a8b1a1466c1eb5899b15 |
File details
Details for the file fibers-1.1.0-cp34-cp34m-win_amd64.whl
.
File metadata
- Download URL: fibers-1.1.0-cp34-cp34m-win_amd64.whl
- Upload date:
- Size: 14.2 kB
- Tags: CPython 3.4m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c105d8665a48a2ccbacd2217bbaa8f113225ebba72bec89c999d33c8844cee03 |
|
MD5 | 4055ed869b213201f3c6d2238534e23f |
|
BLAKE2b-256 | 5c91fa1adbd68084b727dcd514289ac5f4de90cd191258202afa64d0c77acb2b |
File details
Details for the file fibers-1.1.0-cp34-cp34m-win32.whl
.
File metadata
- Download URL: fibers-1.1.0-cp34-cp34m-win32.whl
- Upload date:
- Size: 13.9 kB
- Tags: CPython 3.4m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65b5514a2a1905e7b3497abc26ba5bb11bd324d304174d90f7cfefd348373f20 |
|
MD5 | 9a2fb572fa3b787b42a56e69fbda3286 |
|
BLAKE2b-256 | 4d9f37e59266ff7d364f39255e349b457c360d43c4db719f5909fcfd15306a1c |
File details
Details for the file fibers-1.1.0-cp33-cp33m-win_amd64.whl
.
File metadata
- Download URL: fibers-1.1.0-cp33-cp33m-win_amd64.whl
- Upload date:
- Size: 14.2 kB
- Tags: CPython 3.3m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fdb8be79578936c48c7b4c98229ee75b0048a4a4475438e2179ba1165bd22e4 |
|
MD5 | f325defc09b20612ecb7de12d08dc49e |
|
BLAKE2b-256 | 4fec4030ba89ca323ae411e82b5b7738b0a68730404246bdcb3a811298aba99c |
File details
Details for the file fibers-1.1.0-cp33-cp33m-win32.whl
.
File metadata
- Download URL: fibers-1.1.0-cp33-cp33m-win32.whl
- Upload date:
- Size: 13.9 kB
- Tags: CPython 3.3m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 211ad4888ba7a3ab6ebfedd3b2739c217f437f8c391470feaa6f84caf3843285 |
|
MD5 | 740ccfa3ced0cc1f59723f64c19a3035 |
|
BLAKE2b-256 | a5f1261f3f4844080913e0b20419fd249d99501682c38ab33744f585eed82ada |
File details
Details for the file fibers-1.1.0-cp27-cp27m-win_amd64.whl
.
File metadata
- Download URL: fibers-1.1.0-cp27-cp27m-win_amd64.whl
- Upload date:
- Size: 14.3 kB
- Tags: CPython 2.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83cabfee73774dd4fa7ecd7ed22a7709674a13800bb6a95ca2d61744f259bdee |
|
MD5 | f8655a85e1f8a67833f62174b9b09097 |
|
BLAKE2b-256 | d2a19849a0d79c3463ed19893fd726fa569b24ac619d0a5bd75c060e8da4434a |
File details
Details for the file fibers-1.1.0-cp27-cp27m-win32.whl
.
File metadata
- Download URL: fibers-1.1.0-cp27-cp27m-win32.whl
- Upload date:
- Size: 14.0 kB
- Tags: CPython 2.7m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be6d6dfb308294482db2f5b81be51d078636eac2621f55b09f1501ed5bed3337 |
|
MD5 | d5efce90940028cb5de156599869a5f5 |
|
BLAKE2b-256 | 5b8080917c0750a84a5fa23fba37ebb62973e7c0fc91c721af574c3d4c67093c |