Documentation for pulsar 0.9.2. For development docs, go here.
This is the most important pulsar application. The server is a specialized socket server for web applications conforming with the python web server gateway interface (WSGI 1.0.1). The server can be used in conjunction with several web frameworks as well as pulsar wsgi application handlers, pulsar router, the pulsar RPC middleware and the websocket middleware.
Note
Pulsar wsgi server is production ready designed to easily handle fast, scalable http applications. As all pulsar applications, it uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. In addition, its multiprocessing capabilities allow to handle the c10k problem with ease.
An example of a web server written with the wsgi
module which responds with Hello World!
for every request:
from pulsar.apps import wsgi
def hello(environ, start_response):
data = b"Hello World!"
response_headers = [('Content-type','text/plain'),
('Content-Length', str(len(data)))]
start_response("200 OK", response_headers)
return [data]
if __name__ == '__main__':
wsgi.WSGIServer(hello).start()
For more information regarding WSGI check the pep3333 specification. To run the application:
python script.py
For available run options:
python script.py --help
pulsar.apps.wsgi.
WSGIServer
(callable=None, load_config=True, **params)[source]¶A WSGI SocketServer
.
pulsar.apps.wsgi.server.
HttpServerResponse
(wsgi_callable, cfg, server_software=None, loop=None)[source]¶Server side WSGI ProtocolConsumer
.
wsgi_callable
¶The wsgi callable handling requests.
headers_sent
¶Available once the headers have been sent to the client.
These are the bytes representing the first response line and the headers
data_received
(data)[source]¶Implements data_received()
method.
Once we have a full HTTP message, build the wsgi environ
and
delegate the response to the wsgi_callable()
function.
start_response
(status, response_headers, exc_info=None)[source]¶WSGI compliant start_response
callable, see pep3333.
The application may call start_response more than once, if and only
if the exc_info
argument is provided.
More precisely, it is a fatal error to call start_response
without
the exc_info
argument if start_response has already been called
within the current invocation of the application.
Parameters: |
|
---|---|
Returns: | The |
HOP_HEADERS
are not considered but no error is raised.
write
(data, force=False)[source]¶The write function returned by the start_response()
method.
Required by the WSGI specification.
Parameters: |
|
---|---|
Returns: | a |
pulsar.apps.wsgi.server.
test_wsgi_environ
(path=None, method=None, headers=None, extra=None, secure=False, loop=None)[source]¶An function to create a WSGI environment dictionary for testing.
Parameters: |
|
---|---|
Params secure: | a secure connection? |
Returns: | a valid WSGI environ dictionary. |