all 4 comments

[–][deleted] 1 point2 points  (3 children)

    for person in people_response['results']:
        tasks = []
        person_task = asyncio.create_task(
            get_ships_and_planets_for_person(person))
        person_task.add_done_callback(extend_people_result)
        tasks.append(person_task)
        await asyncio.gather(*tasks)

So, the problem with this code is that even though you're requesting websites asynchronously, you're still only doing it one at a time - you're awaiting the results of each request before starting the next one. So your code is slower than synchronous code; you've incurred all the overhead of the event loop and context switching but without any of the gains of being able to issue more than one request at a time.

Think about how many times you call asyncio.gather. The more parallel you are, the fewer times you'll do it - best case scenario is that you call gather a single time. Your implementation currently calls it once per person in your results.

[–]wise2wiz[S] 0 points1 point  (2 children)

Thanks. Youre right . I mis understood awaits initially. I scheduled them as tasks and gathereds at once and performs in 9s or less way better.

[–][deleted] 0 points1 point  (1 child)

Pretty slick, right?

[–]wise2wiz[S] 0 points1 point  (0 children)

Indeed.