Editor

Concurrency Decision Maker

Advanced · Write the code · from Python Threading vs Multiprocessing vs asyncio: When to Use What

From the lesson: Python Threading vs Multiprocessing vs asyncio: When to Use What

Most programs you've written so far do one thing at a time. But real applications need to handle multiple tasks: downloading files while updating a progress bar, serving web requests from many users, or crunching numbers across all CPU cores.

Read the lesson

Write a function classify_task(description) that takes a task description string and returns the recommended concurrency tool.

Rules:

  • If the description contains "download", "request", "api", or "file" (case-insensitive), return "threading"
  • If the description contains "calculate", "process", "compute", or "analyze" (case-insensitive), return "multiprocessing"
  • If the description contains "server", "websocket", or "connections" (case-insensitive), return "asyncio"
  • Otherwise, return "sequential"
  • Test with these descriptions:

  • "Download 100 files from S3"
  • "Calculate prime numbers"
  • "Handle 5000 WebSocket connections"
  • "Print hello world"
  • # Write the classify_task function
    # Test with the four descriptions

    More Concurrency exercises

    All Python exercises · 50 practice problems · Advanced Python quiz