Previous topic

cogen.web.async

This Page

Quick search

Enter search terms or a module, class or function name.

cogen.web.wsgi

This wsgi server is a single threaded, single process server that interleaves the iterations of the wsgi apps - I could add a threadpool for blocking apps in the future.

If you don’t return iterators from apps and return lists you’ll get, at most, the performance of a server that processes requests sequentialy.

On the other hand this server has coroutine extensions that suppose to support use of middleware in your application.

Example app with coroutine extensions:

def wait_app(environ, start_response):
  start_response('200 OK', [('Content-type','text/html')])
  yield "I'm waiting for some signal"
  yield environ['cogen'].core.events.WaitForSignal("abc", timeout=1)
  if isinstance(environ['cogen'].result, Exception):
    yield "Your time is up !"
  else:
    yield "Someone signaled me: %s" % environ['cogen'].result
  • environ[‘cogen’].core is actualy a wrapper that sets environ[‘cogen’].operation with the called object and returns a empty string. This should penetrate most of the middleware - according to the wsgi spec, middleware should pass a empty string if it doesn’t have anything to return on that specific iteration point, or, in other words, the length of the app iter returned by middleware should be at least that of the app.
  • the wsigi server will set environ[‘cogen’].result with the result of the operation and environ[‘cogen’].exception with the details of the exception - if any: (exc_type, exc_value, traceback_object).

HTTP handling code taken from the CherryPy WSGI server.

class cogen.web.wsgi.WSGIFileWrapper(filelike, blocksize=8192)
class cogen.web.wsgi.WSGIServer(bind_addr, wsgi_app, scheduler, server_name=None, request_queue_size=64, sockoper_timeout=15, sendfile_timeout=-1, sockaccept_greedy=False)

Bases: object

An HTTP server for WSGI.

Option Description
bind_addr

The interface on which to listen for connections. For TCP sockets, a (host, port) tuple. Host values may be any IPv4 or IPv6 address, or any valid hostname. The string ‘localhost’ is a synonym for ‘127.0.0.1’ (or ‘::1’, if your hosts file prefers IPv6). The string ‘0.0.0.0’ is a special IPv4 entry meaning “any active interface” (INADDR_ANY), and ‘::’ is the similar IN6ADDR_ANY for IPv6. The empty string or None are not allowed.

For UNIX sockets, supply the filename as a string.

wsgi_app the WSGI ‘application callable’; multiple WSGI applications may be passed as (path_prefix, app) pairs.
server_name the string to set for WSGI’s SERVER_NAME environ entry. Defaults to socket.gethostname().
request_queue_size the ‘backlog’ argument to socket.listen(); specifies the maximum number of queued connections (default 5).
protocol the version string to write in the Status-Line of all HTTP responses. For example, “HTTP/1.1” (the default). This also limits the supported features used in the response.
ConnectionClass
alias of WSGIConnection
bind(family, type, proto=0)
Create (or recreate) the actual socket object.
bind_addr

The interface on which to listen for connections.

For TCP sockets, a (host, port) tuple. Host values may be any IPv4 or IPv6 address, or any valid hostname. The string ‘localhost’ is a synonym for ‘127.0.0.1’ (or ‘::1’, if your hosts file prefers IPv6). The string ‘0.0.0.0’ is a special IPv4 entry meaning “any active interface” (INADDR_ANY), and ‘::’ is the similar IN6ADDR_ANY for IPv6. The empty string or None are not allowed.

For UNIX sockets, supply the filename as a string.

serve()
Run the server forever.
class cogen.web.wsgi.WSGIConnection(sock, wsgi_app, environ, sockoper_timeout, sendfile_timeout)

Bases: object

render_headers()
run()
A bit bulky atm...
simple_response(status, msg='')
Return a operation for writing simple response back to the client.
start_response(status, headers, exc_info=None)
WSGI callable to begin the HTTP response.
cogen.web.wsgi.server_factory(global_conf, host, port, **options)

Server factory for paste.

Options are:
  • proactor: class name to use from cogen.core.proactors (default: DefaultProactor - best available proactor for current platform)
  • proactor_resolution: float
  • sched_default_priority: int (see cogen.core.util.priority)
  • sched_default_timeout: float (default: 0 - no timeout)
  • server_name: str
  • request_queue_size: int
  • sockoper_timeout: float (default: 15 - operations timeout in 15 seconds), -1 (no timeout), 0 (use scheduler’s default), >0 (seconds)
  • sendfile_timeout: float (default: 300) - same as sockoper_timeout, only applied to sendfile operations (wich might need a much higher timeout value)
  • sockaccept_greedy: bool