← Millennium Interview Insights
Three parts to this and I fumbled the first one a bit.
Start by diagnosing the broken program: identify the missing event loop or unawaited coroutines causing silent exit, then fix it by properly running the async main with asyncio.run. Next, refactor to run both API calls concurrently using asyncio.gather with return_exceptions=True, and explain how to handle cancellation and exceptions robustly.
Pro tip: Emphasize that asyncio.gather with return_exceptions=True prevents one failure from cancelling other tasks, and always wrap the main coroutine in a try/except to handle KeyboardInterrupt and cleanup gracefully.
Check if the async functions are defined but never awaited, or if the event loop is not running. Common causes: missing asyncio.run(main()) or calling coroutines without await.
Wrap the main logic in an async def main() and run it with asyncio.run(main()). Ensure all coroutines are awaited and the event loop is properly closed.
Use asyncio.gather to schedule both API calls simultaneously. Optionally use asyncio.create_task for more control, and await them together.
Pass return_exceptions=True to gather to collect exceptions without cancelling other tasks. Use try/except around await points and handle asyncio.CancelledError to perform cleanup.
Discuss when to use gather vs. wait vs. TaskGroup, how to set timeouts with asyncio.wait_for, and the importance of structured concurrency for reliability.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.