GithubHelp home page GithubHelp logo

saghul / python-fibers Goto Github PK

View Code? Open in Web Editor NEW
160.0 8.0 12.0 125 KB

Lightweight cooperative microthreads for Python

Home Page: https://python-fibers.readthedocs.io

License: Other

Shell 0.06% Python 31.92% C 64.46% Assembly 3.56%
python tasklet stacklet greenlet coroutines

python-fibers's Introduction

fibers: lightweight concurrent multitasking

image

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 above 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

image

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:

python setup.py build_ext --inplace

Running the test suite

The test suite can be run using pytest:

python -m pytest -v .

Author

Saúl Ibarra Corretgé <[email protected]>

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 >= 3.7 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.