Python: when sending email, always blocked in the clause: smtpserver = smtplib.SMTP(“smtp.gmail.com”,587)

前端 未结 4 1940
轮回少年
轮回少年 2021-01-19 08:40

I am writing a Python program to send an email. But every time when executing the clause:

smtpserver = smtplib.SMTP(\"smtp.gmail.com\",587)

4条回答
  •  盖世英雄少女心
    2021-01-19 08:58

    For reference, cpython smtplib is blocking. That is, it blocks the GIL (ie Python) while connecting. Despite the claims the GIL is released on I/O, it is only released on some I/O, and SMTP connections are not such. To make it async, you need to hand the mail send to another process or thread, depending on your situation.

提交回复
热议问题