Bird
0
0

You wrote this async Django view:

medium📝 Debug Q14 of 15
Django - Async Django
You wrote this async Django view:
async def cpu_task(request):
    result = heavy_calculation()
    return JsonResponse({'value': result})

Why might this cause performance issues?
ABecause heavy_calculation() is synchronous and blocks the event loop
BBecause async views cannot return JsonResponse
CBecause async views must not have return statements
DBecause heavy_calculation() is awaited incorrectly
Step-by-Step Solution
Solution:
  1. Step 1: Identify sync call inside async view

    The function heavy_calculation() is synchronous and CPU-heavy, called without await.
  2. Step 2: Understand impact on async event loop

    This blocks the async event loop, preventing other tasks from running concurrently, hurting performance.
  3. Final Answer:

    Because heavy_calculation() is synchronous and blocks the event loop -> Option A
  4. Quick Check:

    Sync CPU work blocks async loop = B [OK]
Quick Trick: Sync CPU tasks block async event loop, causing lag [OK]
Common Mistakes:
MISTAKES
  • Thinking async views can't return JsonResponse
  • Believing return statements are forbidden in async views
  • Assuming heavy_calculation() is awaited automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes