title: how to get return value of async coroutine python
body: <p>I am new to python and trying to learn asyncio module. I am frustrated on getting return values from async tasks. There is a post <a href="https://stackoverflow.com/questions/32456881/getting-values-from-functions-that-run-as-asyncio-tasks">here</a> talked about this topic, but it can't tell which value is returned by which task(assuming some one web page response faster than another).<br />
  The code below is trying to fetch three web pages concurrently instead of doing it one by one.</p>
  <pre><code>    import asyncio
      import aiohttp
  
      async def fetch(url):
          async with aiohttp.ClientSession() as session:
              async with session.get(url) as resp:
                  assert resp.status == 200
                  return await resp.text()
  
      def compile_all(urls):
          tasks = []
          for url in urls:
              tasks.append(asyncio.ensure_future(fetch(url)))
          return tasks
  
      urls = ['https://python.org', 'https://google.com', 'https://amazon.com']
      tasks = compile_all(urls)
      loop = asyncio.get_event_loop()
      a, b, c = loop.run_until_complete(asyncio.gather(*tasks))
      loop.close()
  
      print(a)
      print(b)
      print(c)
  </code></pre>
  <p>First, it hit Runtimeerror though it did print some html documents:  RuntimeError: Event loop is closed.</p>
  <p>Second, question is: does this really guarantee that a, b, c will be corresponded to the urls list in sequence of urls[0], url[1], urls[2] web page? (I assume that async tasks execution won't guarantee that).</p>
  <p>Third, any other better means or Should I use Queue in this case? if yes, how?</p>
  <p>Any help will be greatly appreciated.</p>