• Stars
    star
    160
  • Rank 227,117 (Top 5 %)
  • Language
    C
  • License
    Other
  • Created almost 11 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight cooperative microthreads for Python

fibers: lightweight concurrent multitasking

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:

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é <[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 >= 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.

More Repositories

1

txiki.js

A tiny JavaScript runtime
C
2,343
star
2

pyuv

Python interface for libuv
C
1,112
star
3

pythonz

Python installation manager supporting CPython, Stackless, PyPy and Jython
Python
749
star
4

aiodns

Simple DNS resolver for asyncio
Python
514
star
5

sipp-scenarios

SIPp scenarios I use for testing SIP stuff
256
star
6

lxd-alpine-builder

Build Alpine Linux images for LXD
Shell
168
star
7

pycares

Python interface for c-ares
Python
157
star
8

uvent

A gevent core implemented using libuv
Python
136
star
9

wasi-lab

Some WASI experiments 🧪☣️☠️
C
116
star
10

evergreen

Cooperative multitasking and i/o for Python
Python
114
star
11

CallRoulette

A WebRTC demo using Python (asyncio + aiohttp) as the backend
JavaScript
103
star
12

sjs

Skookum JS: a JavaScript runtime
C
97
star
13

tornaduv

Tornado IOLoop implemented with pyuv
Python
96
star
14

aiouv

A PEP-3156 compatible event loop
Python
71
star
15

uvwsgi

Python WSGI server
Python
37
star
16

qrfcview-osx

RFC viewer for OSX
C++
36
star
17

node-abstractsocket

Abstract namespace socket support for Node
JavaScript
24
star
18

libuv-chat

Something something libuv something
C
21
star
19

twisted-pyuv

Twisted reactor implemented with pyuv
Python
19
star
20

njk

Powerful portable templating in less than 1MB
C
19
star
21

cordova-plugin-audioroute

iOS audio route change events and more for Cordova
Objective-C
17
star
22

twitterbot

A simple Twitter bot retwitting the given hashtag
Python
14
star
23

TunnelIt

SSH reverse forwarder using Twisted
Python
14
star
24

sipsimple-examples

SIPSIMPLE SDK examples
Python
13
star
25

macOS-setup

My macOS setup, automated with Ansible
Shell
11
star
26

dotvim

My vim configuration
Vim Script
11
star
27

SIPwPing-server

Server providing a simple RESTful API to ping SIP servers
Python
11
star
28

shline

A simple powerline style prompt for my bash shell
Python
10
star
29

tornado-backdoor

Interactive Python interpreter over TCP for Tornado applications
Python
9
star
30

pysophia

WIP: Python (CFFI) bindings for Sophia
Python
9
star
31

jitsi-meet-api

Jitsi Meet external API wrapper
JavaScript
8
star
32

sandbox-html

JavaScript
7
star
33

gyn

Generate You some Ninja
Python
6
star
34

uttp

[Unfinished] libuv based HTTP server
C
6
star
35

dotfiles

My dotfiles
Shell
6
star
36

sylk-in-a-box

SylkServer + Sylk WebRTC client, in a box
Nginx
5
star
37

vim-colortoggle

A ViM plugin for toggling background and color scheme
Vim Script
5
star
38

yass

Yet Another SIP Softphone (archive)
Python
3
star
39

python-imap-prowl

A python script to sendpush notifications when new emails via Prowl push service
3
star
40

evergreen-requests

Evergreen + Requests
Python
3
star
41

notes

Notes about anything and everything
Python
2
star
42

jcfg

Jinja templates for your configuration files
Python
2
star
43

sipstache

The Ultimate Virtual Moustache Toolkit (TM)
Python
2
star
44

python-wsserver

[DEAD] A simple, single threaded WebSocket server
Python
2
star
45

python-asiri

GPIO interface for Asiri board with a MCP230XX chip
Python
1
star
46

python-imaplib2

Python threaded IMAP4 client module by Piers Lauder
Python
1
star
47

gvoice-sip-status

Google App Engine application to query the availability of Google Voice inbound SIP service
Python
1
star
48

docker-nginx-webdav

Docker image using nginx to serve files over WebDAV
1
star
49

sipwping-django

Web frontend for SIPwPing server, based on Django
JavaScript
1
star