Bird
0
0

Given this Flask rq task code snippet:

medium📝 component behavior Q13 of 15
Flask - Background Tasks
Given this Flask rq task code snippet:
from rq import Queue
from redis import Redis

redis_conn = Redis()
queue = Queue(connection=redis_conn)

def add(x, y):
    return x + y

job = queue.enqueue(add, 3, 4)
print(job.result)

What will be printed immediately after running this code?
ANone
B7
CError: job.result not available
D3 + 4
Step-by-Step Solution
Solution:
  1. Step 1: Understand rq job processing

    When a job is enqueued, it runs asynchronously. The result is not ready immediately.
  2. Step 2: Check job.result value right after enqueue

    Immediately after enqueue, job.result is None because the worker hasn't processed it yet.
  3. Final Answer:

    None -> Option A
  4. Quick Check:

    job.result before worker runs = None [OK]
Quick Trick: job.result is None until worker finishes task [OK]
Common Mistakes:
MISTAKES
  • Assuming job.result is ready immediately
  • Expecting synchronous return value
  • Confusing job.result with function return

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes