I'm running the following code which makes 5 requests via aiohttp:
import aiohttp
import asyncio
def fetch_page(url, idx):
try:
url = 'http://google.com'
response = yield from aiohttp.request('GET', url)
print(response.status)
except Exception as e:
print(e)
def main():
try:
url = 'http://google.com'
urls = [url] * 5
coros = []
for idx, url in enumerate(urls):
coros.append(asyncio.Task(fetch_page(url, idx)))
yield from asyncio.gather(*coros)
except Exception as e:
print(e)
if __name__ == '__main__':
try:
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
except Exception as e:
print(e)
Output:
200
200
200
200
200
Exception ignored in: Exception ignored in: Exception ignored in: Exception ignored in: Exception ignored in:
Note: There is no additional information as to what/where the exception is.
What's causing this and are there any tips to debug it?
try: ... except Exception
is not best practice. What are you running this code in - is the "Exception ignored" message from your IDE? – Revolutiontry... except
present. I'm thinking that something inaiohttp
orasyncio
is muting out the exceptions. I'm running this in a script executed via terminal in Python 3.4. – Genesisgenetasyncio
application. Are you using Python 3.4.3? – Estabrookresponse.close()
at the end offetch_page
, andloop.close()
after theloop.run_until_complete(..)
line, and see if that makes a difference. – Estabrookresponse.close()
fixed it. Will you add that as an answer so I can accept? – Genesisgenet