Giter Site home page Giter Site logo

conpig's Introduction

Conpig Threading Library

Conpig is a green threading library using green threads from Gevent which are based on greenlets. along side a signal based scheduler. This allows one true concurrency using green threads instead of OS processes or OS threads such that spawning a new thread is still cheap.

Want

  • Fast, cheap, easy, traditional concurrency.

Have

  • Cpython's GIL prevents OS threads from running concurrently and switching context for any reason but to perform IO.

  • OS threads are bulky and slow. Processes are even worse.

  • Current green thread implementations require manual context switches. This is tedious. This is also bug prone for programmers who are used to having a scheduler.

  • Processes based libraries like parallel python prevent you from communicating between "threads" with the datastructures you'd usually use. Again, processes are also slow and buggy.

Solution

  • Create a global scheduler using signals to schedule the next context switch.

Drawbacks & Limitations

  • A solution to concurrency, not parallelism.

  • Conpig threads still can only run on one core of a processor.

  • Context switches still only occur every CPython tick.

  • You still need cooperative yields if you want true fairness for programs that don't do as much IO.

Installing (pip to come)

  1. Install Greenlet with pip.

  2. Install Gevent

    • The old version depends on libevent. The new github version depends on libev
    • On OSX the install path for libevent is wrong even if you use Mac Ports.
    • The easiest install method is to download v.1 from github, and install from source using the provided "setup.py".

Usage

  • You can run from a main method
import conpig

def test(arg):
    for i in range(0,4000):
        print arg


conpig.spawn(test, "X")    
conpig.spawn(test, "O")

conpig.wait_all()

Authors

  • Matthew Mirman

  • Eric Faust

License

See LICENSE file.

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.