Bird
0
0

You want to build a Django app that updates the UI in real-time when Redis messages arrive. Which approach best keeps the app responsive while receiving messages?

hard📝 state output Q15 of 15
Django - Celery and Background Tasks
You want to build a Django app that updates the UI in real-time when Redis messages arrive. Which approach best keeps the app responsive while receiving messages?
AUse Redis publish without subscribing to any channel
BRun the Redis subscribe listen loop in a separate background thread
CCall pubsub.listen() directly in the main Django view function
DStore messages in Django database and poll every minute
Step-by-Step Solution
Solution:
  1. Step 1: Identify the need for responsiveness

    The app must stay responsive while waiting for Redis messages.
  2. Step 2: Choose non-blocking message listening

    Running the listen loop in a background thread prevents blocking the main app thread.
  3. Step 3: Evaluate other options

    Calling listen() in main thread blocks; publishing without subscribing misses messages; polling is slow and inefficient.
  4. Final Answer:

    Run the Redis subscribe listen loop in a separate background thread -> Option B
  5. Quick Check:

    Background thread keeps app responsive [OK]
Quick Trick: Use background thread for listening to avoid blocking UI [OK]
Common Mistakes:
MISTAKES
  • Running listen() in main thread causing freeze
  • Ignoring subscription and only publishing
  • Using slow polling instead of real-time updates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes