Documentation for pulsar 0.9.2. For development docs, go here.
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: | ![]() ![]() |
---|---|
Dev CI: | ![]() ![]() |
Documentation: | http://pythonhosted.org/pulsar/ |
Downloads: | http://pypi.python.org/pypi/pulsar |
Source: | https://github.com/quantmind/pulsar |
Mailing list: | google user group |
Design by: | Quantmind and Luca Sbardella |
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.
Pulsar requires and install the following packages:
Install via pip
:
pip install pulsar
or downloading the tarball from pypi.
If cython is available, c extensions will be compiled and installed.
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:
Check out the examples
directory for various working applications.
It includes:
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.
Pulsar checks if some additional libraries are available at runtime, and uses them to add additional functionalities or improve performance:
system
key is available in the dictionary
returned by Actor info method.json
module.pulsar.apps.pulse
application.slugify
functionPulsar test suite uses the pulsar test application. If not running on python 3.4 or above the mock is 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 pulsar
Pulsar project started as a fork of gunicorn and since version 0.5 has been implemented on top of asyncio (tulip and PEP-3156). Pulsar uses several snippet of code from around the open-source community, in particular:
Development of pulsar happens at Github. We very much welcome your contribution of course. To do so, simply follow these guidelines:
git checkout -b my_branch
git push origin my_branch
A good pull
request should:
Cover one bug fix or new feature only
Include tests to cover the new code (inside the tests
directory)
Preferably have one commit only (you can use rebase to combine several commits into one)
Make sure pep8
tests pass:
python runtests.py --pep8 pulsar examples tests