Bird
0
0

Identify the error in this code for scaling agents horizontally:

medium📝 Debug Q6 of 15
Agentic AI - Production Agent Architecture
Identify the error in this code for scaling agents horizontally:
from threading import Thread

agents = [Agent(i) for i in range(3)]
threads = [Thread(target=agent.run) for agent in agents]
for t in threads:
    t.run()
AMissing import for Agent class.
BThreads are not created correctly.
CUsing t.run() instead of t.start() prevents parallel execution.
DNo error; code runs fine.
Step-by-Step Solution
Solution:
  1. Step 1: Understand difference between run() and start()

    Calling run() executes in current thread, no parallelism.
  2. Step 2: Identify correct method to start threads

    start() must be called to run threads concurrently.
  3. Final Answer:

    Using t.run() instead of t.start() prevents parallel execution. -> Option C
  4. Quick Check:

    Use start() to run threads in parallel [OK]
Quick Trick: Use start(), not run(), to launch threads [OK]
Common Mistakes:
  • Confusing run() with start()
  • Ignoring missing imports (not shown here)
  • Assuming run() starts a new thread

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes