F
Frank Millman
Hi all
I am trying to get to grips with asyncio, but I don't know if I am doing it
right.
I have an app that listens for http connections and sends responses. I had
it working
with cherrypy, which uses threading. Now I am trying to convert it to
asyncio,
using a package called aiohttp.
I got a basic version working quite quickly, just replacing cherrpy's
request handler with aiohttp's, with a bit of tweaking where required.
Now I want to use the functionality of asyncio by using a 'yield from' to
suspend the currently executing function at a particular point while it
waits for some information. I find that adding 'yield from' turns the
function into a generator, which means that the caller has to iterate over
it. I can avoid that by telling the caller to 'yield from' the generator,
but then *its* caller has to be modified. Now I find I am going through my
entire application and changing every function into a coroutine by
decorating it with @asyncio.coroutine, and changing a simple function call
to a 'yield from'.
So far it is working, but there are dozens of functions to modify, so before
digging too deep a hole for myself I would like to know if this feels like
the right approach.
Thanks
Frank Millman
I am trying to get to grips with asyncio, but I don't know if I am doing it
right.
I have an app that listens for http connections and sends responses. I had
it working
with cherrypy, which uses threading. Now I am trying to convert it to
asyncio,
using a package called aiohttp.
I got a basic version working quite quickly, just replacing cherrpy's
request handler with aiohttp's, with a bit of tweaking where required.
Now I want to use the functionality of asyncio by using a 'yield from' to
suspend the currently executing function at a particular point while it
waits for some information. I find that adding 'yield from' turns the
function into a generator, which means that the caller has to iterate over
it. I can avoid that by telling the caller to 'yield from' the generator,
but then *its* caller has to be modified. Now I find I am going through my
entire application and changing every function into a coroutine by
decorating it with @asyncio.coroutine, and changing a simple function call
to a 'yield from'.
So far it is working, but there are dozens of functions to modify, so before
digging too deep a hole for myself I would like to know if this feels like
the right approach.
Thanks
Frank Millman