Skip to main content

Lightweight cooperative microthreads for Pyhton

Project description

https://badge.fury.io/py/fibers.png

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

https://secure.travis-ci.org/saghul/python-fibers.png?branch=master https://ci.appveyor.com/api/projects/status/9f4h0wk797i4vc0k?svg=true

Documentation

http://readthedocs.org/docs/python-fibers/

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 (with Visual Studio 2008 or 2010):

python setup.py build_ext --inplace

Running the test suite

The test suite can be run using nose:

nosetests -v

Author

Saúl Ibarra Corretgé <saghul@gmail.com>

This project would not have been possible without the previous work done in the greenlet and stacklet (part of PyPy) projects.

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 and MIPS64 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

fibers-1.0.0.tar.gz (34.6 kB view details)

Uploaded Source

Built Distributions

fibers-1.0.0-cp34-none-win_amd64.whl (13.7 kB view details)

Uploaded CPython 3.4 Windows x86-64

fibers-1.0.0-cp34-none-win32.whl (13.5 kB view details)

Uploaded CPython 3.4 Windows x86

fibers-1.0.0-cp33-none-win_amd64.whl (13.7 kB view details)

Uploaded CPython 3.3 Windows x86-64

fibers-1.0.0-cp33-none-win32.whl (13.5 kB view details)

Uploaded CPython 3.3 Windows x86

fibers-1.0.0-cp27-none-win_amd64.whl (13.8 kB view details)

Uploaded CPython 2.7 Windows x86-64

fibers-1.0.0-cp27-none-win32.whl (13.5 kB view details)

Uploaded CPython 2.7 Windows x86

File details

Details for the file fibers-1.0.0.tar.gz.

File metadata

  • Download URL: fibers-1.0.0.tar.gz
  • Upload date:
  • Size: 34.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fibers-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1bda7f8fd6adf738c2ffe31d29abeceedf19bf1146cc7bfb08a0ebafbbb30067
MD5 97940b5d6a9a835c1f40d69ff20e93db
BLAKE2b-256 fd07c3590e88403ddbba73be381bbdf064113de099c26b17e3337c626c5fc21a

See more details on using hashes here.

File details

Details for the file fibers-1.0.0-cp34-none-win_amd64.whl.

File metadata

File hashes

Hashes for fibers-1.0.0-cp34-none-win_amd64.whl
Algorithm Hash digest
SHA256 965df14af32bd27c38218e913ebf1757911bd4bb8bf2707fd81d473c2c5d03bd
MD5 cd1cbc79459111a5444a1218233e54b9
BLAKE2b-256 2745c939ab6deac6e9c62b8638e76b9cd85a36dba2a25e9368df27142761df37

See more details on using hashes here.

File details

Details for the file fibers-1.0.0-cp34-none-win32.whl.

File metadata

File hashes

Hashes for fibers-1.0.0-cp34-none-win32.whl
Algorithm Hash digest
SHA256 5d0f701181a280e8948e797fbd2e811b2d0b3d03ec4d32e59b61c73cf611bf4f
MD5 e4659c19224f3d4fa471b75d2739d2d2
BLAKE2b-256 a2a97fc18b4ded9ba01adcf22be0165014e641bd9d8d3e79fa01bc0fbfcb6f80

See more details on using hashes here.

File details

Details for the file fibers-1.0.0-cp33-none-win_amd64.whl.

File metadata

File hashes

Hashes for fibers-1.0.0-cp33-none-win_amd64.whl
Algorithm Hash digest
SHA256 8b3f8a3efdf39f0eada1ff01f7aa8490d58cd2a2dd3618794f1e6e7af43639bc
MD5 feacb6891d0d293d6a2b03664dfbf1fd
BLAKE2b-256 2e80bf877fdb0449299ec7317bb5821ea8caccfa078a8273c0494f8eed0e1b17

See more details on using hashes here.

File details

Details for the file fibers-1.0.0-cp33-none-win32.whl.

File metadata

File hashes

Hashes for fibers-1.0.0-cp33-none-win32.whl
Algorithm Hash digest
SHA256 225632ee5bdcbf1a3da2e65543d36c0407d19cdf041a570f186bd70a0383d376
MD5 db384176cea46b812328530873d681b2
BLAKE2b-256 7e2cb5bbe16a8aa02f46e3c444a76affd4d240fac6e42c1ce94fab2e55cc93e9

See more details on using hashes here.

File details

Details for the file fibers-1.0.0-cp27-none-win_amd64.whl.

File metadata

File hashes

Hashes for fibers-1.0.0-cp27-none-win_amd64.whl
Algorithm Hash digest
SHA256 5466d39440c615c58933c25ebdd3197b8dbb3fd15886bfa48e26f79b1841eb26
MD5 feb1dff03ea8caa68361b219df811b38
BLAKE2b-256 3adebe5938f36073d8d61b76cbbf49a4c93d7ad5daa65e44f9301d3411acf969

See more details on using hashes here.

File details

Details for the file fibers-1.0.0-cp27-none-win32.whl.

File metadata

File hashes

Hashes for fibers-1.0.0-cp27-none-win32.whl
Algorithm Hash digest
SHA256 2d52013b6f15816f3e81698f8938967b3a6ba25770ac5faca89e17a63b110b90
MD5 b3104f0e08bfe0f7f56599c40c298cd1
BLAKE2b-256 3a9673becd198004d5c2c3c314d7a4cdd1c3bb7ff50175b9d2aa384dcda1a4db

See more details on using hashes here.

Supported by

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