I have a route that sends a number of emails. To avoid rate limits, I am using time.sleep(1)
between emails. If I understand correctly, the route will run in its own thread or coroutine and this will not block other requests, but I thought it would be good to confirm this with the community. Here is a code example (simplified to focus on the issue):
@router.get("/send_a_bunch_of_emails")
def send_a_bunch_of_emails(db: Session = Depends(get_db)):
users = get_a_bunch_of_users(db)
for user in users:
send_email(to=user.email)
time.sleep(1) # Maximum of 1 email per second
I am just wanting to confirm, that if hypothetically, this sent 10 emails, it wouldn't block FastAPI for 10 seconds. Based on my testing this doesn't appear to be the case, but I'm wary of gotchas.