Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103543 > unrolled thread

Re: Looking for examples of using aiopg with aiohttp and non-async startup.

Started byRay Cote <rgacote@appropriatesolutions.com>
First post2016-02-26 09:52 -0500
Last post2016-02-26 09:52 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Looking for examples of using aiopg with aiohttp and non-async startup. Ray Cote <rgacote@appropriatesolutions.com> - 2016-02-26 09:52 -0500

#103543 — Re: Looking for examples of using aiopg with aiohttp and non-async startup.

FromRay Cote <rgacote@appropriatesolutions.com>
Date2016-02-26 09:52 -0500
SubjectRe: Looking for examples of using aiopg with aiohttp and non-async startup.
Message-ID<mailman.153.1456498366.20994.python-list@python.org>
Answer (obvious after a refreshing sleep):
Just run a separate async pool connection prior to kicking off the aiohttp
web application.
The startup now looks like:

async def connect():
    return await aiopg.create_pool(…)

if __name__ == “__main__”:
    loop = asyncio.get_event_loop()
    pool = loop.run_until_complete(connect())
    app = web.Application()
    app["pool"] = pool
    app.router.add_route(‘POST', '/pv/v1/', handle_v1)
    web.run_app(app)


Then, in the handle_v1 code:
    pool = request.app["pool"]
    connection = await pool.acquire()
    cursor = await connection.cursor()
—r

On Thu, Feb 25, 2016 at 5:23 PM, Ray Cote <rgacote@appropriatesolutions.com>
wrote:

> Hello:
>
> I have an aiohttp project that starts in the usual way:
>
> app = web.Application()
> app.router.add_route(‘POST”, ‘/‘, handler)
> web.run_app(app)
>
> My question is, how do I work with an aiopg.pool with aiohttp?
> There only seems to be async interfaces into aiopg — but I don’t want to
> create the pool in my handler since that requires a connection on each
> transaction.
>
> I found one example that was
>   app[“db”] = await aiopg.create_pool(dsn)
> but that doesn’t seen correct since we’re not yet in a loop.
>
> Can someone please provide an example showing the proper way to integrate
> aiopg pool into an aiohttp web application?
>
> Regards
> —Ray
>
> --
> Raymond Cote, President
> voice: +1.603.924.6079 email: rgacote@AppropriateSolutions.com skype:
> ray.cote
>
>
>


-- 
Raymond Cote, President
voice: +1.603.924.6079 email: rgacote@AppropriateSolutions.com skype:
ray.cote

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web