aiopyramid

Module contents

Run pyramid app using asyncio

aiopyramid.includeme(config)[source]

Setup the basic configuration to run Pyramid with asyncio.

Submodules

aiopyramid.config module

This module provides view mappers for running views in asyncio.

class aiopyramid.config.AsyncioMapperBase(**kw)[source]

Bases: pyramid.config.views.DefaultViewMapper

Base class for asyncio view mappers.

run_in_coroutine_view(view)[source]
run_in_executor_view(view)[source]
class aiopyramid.config.CoroutineMapper(**kw)[source]

Bases: aiopyramid.config.AsyncioMapperBase

class aiopyramid.config.CoroutineOrExecutorMapper(**kw)[source]

Bases: aiopyramid.config.AsyncioMapperBase

class aiopyramid.config.ExecutorMapper(**kw)[source]

Bases: aiopyramid.config.AsyncioMapperBase

aiopyramid.exceptions module

exception aiopyramid.exceptions.ScopeError[source]

Bases: Exception

Error indicating execution in the wrong greenlet.

aiopyramid.helpers module

aiopyramid.helpers.is_generator(func)[source]

Tests whether func is capable of becoming an asyncio.coroutine.

aiopyramid.helpers.run_in_greenlet(back, future, func, *args, **kwargs)[source]

Wait for coroutine func and switch back to the request greenlet setting any result in the future or an Exception where approrpiate.

func is often a view callable

aiopyramid.helpers.spawn_greenlet(func, *args, **kwargs)[source]

Spawns a new greenlet and waits on any asyncio.Future objects returned.

This is used by the Gunicorn worker to proxy a greenlet within an asyncio event loop.

aiopyramid.helpers.spawn_greenlet_on_scope_error(func)[source]

Wraps a callable handling any ScopeErrors that may occur because the callable is called from inside of a coroutine.

If no ScopeError occurs, the callable is executed normally and return arguments are passed through, otherwise, when a ScopeError does occur, a coroutine to retrieve the result of the callable is returned instead.

aiopyramid.helpers.synchronize(*args, strict=True)[source]

Decorator for transforming an async coroutine function into a regular function relying on the aiopyramid architecture to schedule the coroutine and obtain the result.

@synchronize
@asyncio.coroutine
def my_coroutine():
    ... code that yields
aiopyramid.helpers.use_executor(*args, executor=None)[source]

A decorator for running a callback in the executor.

This is useful to provide a declarative style for converting some thread-based code to a coroutine. It creates a coroutine by running the wrapped code in a separate thread.

aiopyramid.traversal module

The aiopyramid.traversal module is deprecated, use aiopyramid.helpers.synchronize instead. See http://aiopyramid.readthedocs.io/features.html#traversal.

aiopyramid.tweens module

The aiopyramid.tweens module is deprecated. See example in the docs: http://aiopyramid.readthedocs.io/features.html#tweens.

aiopyramid.tweens.coroutine_logger_tween_factory(handler, registry)[source]

Example of an asynchronous tween that delegates a synchronous function to a child thread. This tween asynchronously logs all requests and responses.