Tornado Coroutine : Return value and one time execution
<p>I'm new to Tornado so I wanted to know if the code below is a correct way to approach the problem or there is a better one. It works but I'm not sure regarding its efficiency. </p>

<p>The code is based on the documentation <a href="http://www.tornadoweb.org/en/stable/guide/coroutines.html" rel="nofollow">here</a></p>

<p>In the middle of my script, I need to run HTTP Requests (10-50). Apparently, it is possible to do this in parallel this way :</p>

<pre><code>@gen.coroutine
def parallel_fetch_many(urls):
    responses = yield [http_client.fetch(url) for url in urls]
    # responses is a list of HTTPResponses in the same order
</code></pre>

<p>How do I access responses after the coroutine is done ? Can I just add <code>return responses</code> ?
Also, as I only need to use an async process once in my code, I start the IOLoop this way :</p>

<pre><code># run_sync() doesn't take arguments, so we must wrap the
# call in a lambda.
IOLoop.current().run_sync(lambda: parallel_fetch_many(googleLinks))
</code></pre>

<p>Is it correct to do it this way ? Or should I just start the IOLoop at the beginning of the script and stop it a the end, even though I only use an async process once.</p>

<p>Basically, my question is : Is the code below correct ?</p>

<pre><code>@gen.coroutine
def parallel_fetch_many(urls):
    responses = yield [http_client.fetch(url) for url in urls]
    return responses

googleLinks = [url1,url2,...,urln]

responses = IOLoop.current().run_sync(lambda:parallel_fetch_many(googleLinks))

do_something(responses)
</code></pre>

<p>Yes, your code looks correct to me.</p>

python tornado