Bird
0
0

You want to send a confirmation email after a user submits a form in Flask without delaying the response. Which approach best uses background processing to achieve this?

hard📝 Application Q15 of 15
Flask - Background Tasks
You want to send a confirmation email after a user submits a form in Flask without delaying the response. Which approach best uses background processing to achieve this?
AStart a new thread with the email sending function inside the form route, then return response immediately.
BCall the email sending function directly inside the route before returning the response.
CUse a while loop in the route to wait until the email is sent, then return response.
DBlock the route until the email server confirms delivery, then return response.
Step-by-Step Solution
Solution:
  1. Step 1: Identify the goal

    The goal is to send email without making the user wait for the response.
  2. Step 2: Evaluate options

    Starting a new thread for email sending lets the route return immediately, improving user experience. Calling email function directly or blocking causes delay.
  3. Final Answer:

    Start a new thread with the email sending function inside the form route, then return response immediately. -> Option A
  4. Quick Check:

    Background thread sends email; response fast [OK]
Quick Trick: Run slow tasks in thread, return response fast [OK]
Common Mistakes:
MISTAKES
  • Calling slow tasks directly in route causing delay
  • Using loops to wait for task completion
  • Blocking response until external confirmation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes