I am trying to teach myself Python\'s async functionality. To do so I have built an async web scraper. I would like to limit the total number of connections I have open at o
OK, so this is really silly but I just replaces yield from
with await
in the semaphore context manager and it is working perfectly.
sema = asyncio.BoundedSemaphore(5)
async def get_page_text(url):
with (await sema):
try:
resp = await aiohttp.request('GET', url)
if resp.status == 200:
ret_val = await resp.text()
except:
raise ValueError
finally:
await resp.release()
return ret_val