Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] on_startup & on_shutdown signals example with aiopg engine #2196

Merged
merged 3 commits into from
Aug 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/2131.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add example usage of on_startup and on_shutdown signals by creating and disposing an aiopg connection engine.
26 changes: 26 additions & 0 deletions docs/web.rst
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,32 @@ This can be accomplished by subscribing to the
app.on_response_prepare.append(on_prepare)


Additionally, the :attr:`~aiohttp.web.Application.on_startup` and
:attr:`~aiohttp.web.Application.on_cleanup` signals can be subscribed to for
application component setup and tear down accordingly.

The following example will properly initialize and dispose an aiopg connection
engine::

from aiopg.sa import create_engine

async def create_aiopg(app):
app['pg_engine'] = await create_engine(
user='postgre',
database='postgre',
host='localhost',
port=5432,
password=''
)

async def dispose_aiopg(app):
app['pg_engine'].close()
await app['pg_engine'].wait_closed()

app.on_startup.append(create_aiopg)
app.on_cleanup.append(dispose_aiopg)


Signal handlers should not return a value but may modify incoming mutable
parameters.

Expand Down