This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

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

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

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, 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.

Release History

Release History

This version
History Node

1.1.0

History Node

1.0.0

History Node

0.4.0

History Node

0.3.0

History Node

0.2.0

History Node

0.1.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
fibers-1.1.0-cp27-cp27m-win32.whl (14.0 kB) Copy SHA256 Checksum SHA256 cp27 Wheel Jul 21, 2017
fibers-1.1.0-cp27-cp27m-win_amd64.whl (14.3 kB) Copy SHA256 Checksum SHA256 cp27 Wheel Jul 21, 2017
fibers-1.1.0-cp33-cp33m-win32.whl (13.9 kB) Copy SHA256 Checksum SHA256 cp33 Wheel Jul 21, 2017
fibers-1.1.0-cp33-cp33m-win_amd64.whl (14.2 kB) Copy SHA256 Checksum SHA256 cp33 Wheel Jul 21, 2017
fibers-1.1.0-cp34-cp34m-win32.whl (13.9 kB) Copy SHA256 Checksum SHA256 cp34 Wheel Jul 21, 2017
fibers-1.1.0-cp34-cp34m-win_amd64.whl (14.2 kB) Copy SHA256 Checksum SHA256 cp34 Wheel Jul 21, 2017
fibers-1.1.0-cp35-cp35m-win32.whl (15.0 kB) Copy SHA256 Checksum SHA256 cp35 Wheel Jul 21, 2017
fibers-1.1.0-cp35-cp35m-win_amd64.whl (16.3 kB) Copy SHA256 Checksum SHA256 cp35 Wheel Jul 21, 2017
fibers-1.1.0-cp36-cp36m-win32.whl (15.0 kB) Copy SHA256 Checksum SHA256 cp36 Wheel Jul 21, 2017
fibers-1.1.0-cp36-cp36m-win_amd64.whl (16.3 kB) Copy SHA256 Checksum SHA256 cp36 Wheel Jul 21, 2017
fibers-1.1.0.tar.gz (36.1 kB) Copy SHA256 Checksum SHA256 Source Jul 21, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting