Bird
0
0

Consider this Django async view:

medium📝 component behavior Q4 of 15
Django - Async Django
Consider this Django async view:
async def view(request):
    result = await heavy_sync_task()
    return JsonResponse({'result': result})

What issue arises if heavy_sync_task is a CPU-intensive synchronous function?
AThe view raises a syntax error
BThe function runs asynchronously without blocking
CDjango automatically converts it to async
DThe async view blocks the event loop, reducing concurrency
Step-by-Step Solution
Solution:
  1. Step 1: Understand await with sync functions

    Awaiting a synchronous CPU-heavy function blocks the event loop.
  2. Step 2: Impact on async view

    This blocking prevents other async tasks from running concurrently.
  3. Final Answer:

    The async view blocks the event loop, reducing concurrency -> Option D
  4. Quick Check:

    Awaiting sync CPU tasks blocks async event loop [OK]
Quick Trick: Awaiting sync CPU tasks blocks async concurrency [OK]
Common Mistakes:
MISTAKES
  • Assuming sync CPU tasks run asynchronously
  • Expecting Django to auto-convert sync to async

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes