title: Python tornado parallel requests using coroutines and handling exceptions
body: <p>I've started working with python tornado recently.</p>
  
  <p>I've done a small project using callbacks and now 
  I'm trying to figure out how to use coroutines to 
  make my life a bit easier ( or harder )</p>
  
  <p>I have the following code:</p>
  
  <pre><code>from tornado import gen
  
  import random
  import time
  
  class App(object):
  
      @gen.coroutine
      def get_repo_issues(self, repo):
          sleep_time = random.randint(1, 5)
          time.sleep(sleep_time)
  
          if sleep_time in (2, 4):
              raise Exception('There is a disturbance in the force... %d' % sleep_time)
  
          raise gen.Return(sleep_time)
  
  
      @gen.coroutine
      def get_all_repo_issues(self, repo_list):
  
          for i in repo_list:
              repo = 'repo_' + str(i)
              try:
                  items = yield self.get_repo_issues(repo)
                  print 'Got %d items for %s' % (items, repo)
              except Exception as e:
                  print 'Got exception for %s: %s' % (repo, str(e))
  
  
      @gen.coroutine
      def main(self):
          yield gen.Task(self.get_all_repo_issues, range(5))
  
  
  def main():
      App().main()
  </code></pre>
  
  <p>Above code works as intended but I want parallel calls to self.get_repo_issues while catching and treating exceptions.</p>
  
  <p>I was thinking something along the lines of yielding a dictionary of calls but dont know how to catch exceptions.</p>
  
  <p>Is there a way to do this in tornado ?</p>