PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Software Engineering Fundamentals/Millennium

Debug missing output in Python async HTTP flow

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of asynchronous programming in Python, including event loop management and async I/O semantics, and is categorized under Software Engineering Fundamentals with a focus on practical application of concurrency concepts.

  • medium
  • Millennium
  • Software Engineering Fundamentals
  • Software Engineer

Debug missing output in Python async HTTP flow

Company: Millennium

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Onsite

You are given a Python program intended to call two HTTP APIs in order, process the returned JSON, and finally print the computed result. However, when you run the program, it exits without printing the expected output. Assume an async HTTP client (e.g., `aiohttp`) is used. ### Code (simplified) ```python import asyncio import aiohttp async def fetch_json(session, url): async with session.get(url) as resp: return await resp.json() async def pipeline(): async with aiohttp.ClientSession() as session: a = fetch_json(session, "https://api.example.com/a") b = fetch_json(session, "https://api.example.com/b") result = (await a)["value"] + (await b)["value"] print("result:", result) def main(): pipeline() if __name__ == "__main__": main() ``` ### Tasks 1. Explain why the program does not print anything (or prints inconsistently). 2. Show how you would fix it so the API calls actually execute and `print` reliably runs. 3. As a follow-up: if the intent is to run both HTTP calls concurrently, what is the idiomatic way to do that, and what pitfalls should you watch for (e.g., cancellation, exceptions, and program exit)?

Quick Answer: This question evaluates understanding of asynchronous programming in Python, including event loop management and async I/O semantics, and is categorized under Software Engineering Fundamentals with a focus on practical application of concurrency concepts.

Millennium logo
Millennium
Oct 24, 2025, 12:00 AM
Software Engineer
Onsite
Software Engineering Fundamentals
6
0

You are given a Python program intended to call two HTTP APIs in order, process the returned JSON, and finally print the computed result. However, when you run the program, it exits without printing the expected output.

Assume an async HTTP client (e.g., aiohttp) is used.

Code (simplified)

import asyncio
import aiohttp

async def fetch_json(session, url):
    async with session.get(url) as resp:
        return await resp.json()

async def pipeline():
    async with aiohttp.ClientSession() as session:
        a = fetch_json(session, "https://api.example.com/a")
        b = fetch_json(session, "https://api.example.com/b")
        result = (await a)["value"] + (await b)["value"]
        print("result:", result)

def main():
    pipeline()

if __name__ == "__main__":
    main()

Tasks

  1. Explain why the program does not print anything (or prints inconsistently).
  2. Show how you would fix it so the API calls actually execute and print reliably runs.
  3. As a follow-up: if the intent is to run both HTTP calls concurrently, what is the idiomatic way to do that, and what pitfalls should you watch for (e.g., cancellation, exceptions, and program exit)?

Solution

Show

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Software Engineering Fundamentals•More Millennium•More Software Engineer•Millennium Software Engineer•Millennium Software Engineering Fundamentals•Software Engineer Software Engineering Fundamentals
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.