Code Monkey home page Code Monkey logo

pulsar's Introduction

Event driven concurrent framework for python. With pulsar you can write asynchronous servers performing one or several activities in different threads and/or processes.

Master CI

master-build_ coverage-master

Dev CI

dev-build_ coverage-dev

Documentation

http://pythonhosted.org/pulsar/

Downloads

http://pypi.python.org/pypi/pulsar

Source

https://github.com/quantmind/pulsar

Mailing list

google user group

Platforms

Linux, OSX, Windows. Python 2.7, 3.3, 3.4 and pypy

Keywords

client, server, asynchronous, concurrency, actor, thread, process, socket, task queue, wsgi, websocket, redis, json-rpc

An example of a web server written with pulsar which responds with "Hello World!" for every request:

from pulsar.apps import wsgi

def hello(environ, start_response):
    data = b'Hello World!\n'
    response_headers = [
        ('Content-type','text/plain'),
        ('Content-Length', str(len(data)))
    ]
    start_response('200 OK', response_headers)
    return [data]


if __name__ == '__main__':
    wsgi.WSGIServer(callable=hello).start()

Pulsar's goal is to provide an easy way to build scalable network programs. In the Hello world! web server example above, many client connections can be handled concurrently. Pulsar tells the operating system (through epoll or select) that it should be notified when a new connection is made, and then it goes to sleep.

Pulsar uses the multiprocessing module from the standard python library and it can be configured to run in multi-processing mode, multi-threading mode or a combination of the two.

Installing

Pulsar is a stand-alone library for python 3.4 and up.

Pulsar can be installed via `pip`:

pip install pulsar

or downloading the tarball from pypi.

If cython is available, c extensions will be compiled and installed.

Applications

Pulsar design allows for a host of different asynchronous applications to be implemented in an elegant and efficient way. Out of the box it is shipped with the the following:

  • Socket servers
  • WSGI server
  • JSON-RPC
  • Web Sockets
  • Task queue
  • Shell
  • Test suite
  • Data stores
  • django integration

Examples

Check out the examples directory for various working applications. It includes:

  • Hello world! wsgi example
  • An Httpbin wsgi application
  • An HTTP Proxy server
  • A JSON-RPC Calculator server
  • A taskqueue application with a JSON-RPC interface
  • Websocket random graph.
  • Websocket chat room.
  • django web site with a websocket based chat room.
  • A web mail application which uses twisted IMAP4 API.
  • The dining philosophers problem.
  • Asynchronous shell.

Design

Pulsar internals are based on actors primitive. Actors are the atoms of pulsar's concurrent computation, they do not share state between them, communication is achieved via asynchronous inter-process message passing, implemented using the standard python socket library.

Two special classes of actors are the Arbiter, used as a singleton, and the Monitor, a manager of several actors performing similar functions. The Arbiter runs the main eventloop and it controls the life of all actors. Monitors manage group of actors performing similar functions, You can think of them as a pool of actors.

More information about design and philosophy in the documentation.

Add-ons

Pulsar checks if some additional libraries are available at runtime, and uses them to add additional functionalities or improve performance:

  • setproctitle: if installed, pulsar can use it to change the processes names of the running application.
  • psutil: if installed, a system key is available in the dictionary returned by Actor info method.
  • ujson: if installed it is used instead of the native json module.
  • django: required by the pulsar.apps.pulse application.

Running Tests

Pulsar test suite uses the pulsar test application. If you are using python 2.6 you need to install unittest2, and if not running on python 3.3, the mock library is also needed. To run tests:

python runtests.py

For options and help type:

python runtests.py -h

pep8 check (requires pep8 package):

python runtests.py --pep8

Kudos

Pulsar project started as a fork of gunicorn (from where the arbiter idea) and has been developed using ideas from nodejs (api design), twisted (the deferred implementation), tornado web server (the initial event-loop implementation), celery (the task queue application) and, since version 0.5, tulip and PEP-3156. In addition, pulsar uses several snippet of code from around the open-source community, in particular:

  • A python HTTP Parser originally written by benoitc.
  • A url Rule class originally from werkzeug.

Contributing

Development of pulsar happens at Github. We very much welcome your contribution of course. To do so, simply follow these guidelines:

License

This software is licensed under the New BSD License. See the LICENSE file in the top distribution directory for the full license text.

pulsar's People

Contributors

lsbardel avatar etataurov avatar remcoder avatar eventh avatar cyberj avatar dhutty avatar

Watchers

wangliming avatar James Cloos avatar

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.