B. Using thread.run() instead of thread.start() causes the task to run in the main thread.
C. Flask app is not created correctly.
D. The route function must be async to use threads.
Solution
Step 1: Understand difference between run() and start()
thread.run() runs the function in the current thread synchronously; start() runs it in a new thread.
Step 2: Check code usage
Using thread.run() means the task blocks the main thread, defeating background processing purpose.
Final Answer:
Using thread.run() instead of thread.start() causes the task to run in the main thread. -> Option B
Quick Check:
Use thread.start() to run background task [OK]
Hint: Always call thread.start(), not thread.run(), for background tasks [OK]
Common Mistakes:
Calling thread.run() instead of thread.start()
Thinking thread.run() starts a new thread
Believing Flask routes must be async for threading
5. 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
A. Start a new thread with the email sending function inside the form route, then return response immediately.
B. Call the email sending function directly inside the route before returning the response.
C. Use a while loop in the route to wait until the email is sent, then return response.
D. Block the route until the email server confirms delivery, then return response.
Solution
Step 1: Identify the goal
The goal is to send email without making the user wait for the response.
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.
Final Answer:
Start a new thread with the email sending function inside the form route, then return response immediately. -> Option A
Quick Check:
Background thread sends email; response fast [OK]
Hint: Run slow tasks in thread, return response fast [OK]
Common Mistakes:
Calling slow tasks directly in route causing delay
Using loops to wait for task completion
Blocking response until external confirmation
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.