aiosmtplib: SMTP.quit produces warning "Future exception was never retrieved"
I ported this code from my old implementation on standard smtplib module, and perhaps it is not correct for aiosmtplib. But i think this shouldn’t matter.
import asyncio
import aiosmtplib
from email.mime.text import MIMEText
from email.header import Header
async def send_mail(host, login, password, from_addr, to_addr, subject, body_text):
msg=MIMEText(*body_text)
msg['Subject']=Header(subject, 'utf-8')
msg['From']=from_addr
msg['To']=to_addr
server=aiosmtplib.SMTP(host)
await server.connect()
await server.starttls()
await server.login(login, password)
try:
await server.sendmail(from_addr, [to_addr], msg.as_string())
except (aiosmtplib.SMTPRecipientsRefused, aiosmtplib.SMTPSenderRefused):
return 1
finally:
await server.quit()
#code for testing
async def start():
await send_mail('smtp.yandex.ru', 'a@b.c', '1234', 'a@b.c', 'x@y.z', 'Testing', ['Hello', 'plain', 'utf-8'])
print('success')
#emulating work of other asyncio tasks...
await asyncio.sleep(3)
asyncio.run(start())```
```Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
>>> import mail_test
success
>>> exit()
Future exception was never retrieved
future: <Future finished exception=SMTPServerDisconnected('Unexpected EOF received')>
aiosmtplib.errors.SMTPServerDisconnected: Unexpected EOF received```
If i comment two last lines of my function, it works good.
```>>> import mail_test
success
>>> exit()```
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 2
- Comments: 22 (8 by maintainers)
3.0.1 is out 🙂
The
mainbranch works without errors 👍🏻can confirm, latest master version does not produce the error.
win32, 3.11.6I’m eagerly awaiting the patch. Thank you for your prompt responses and work 😃
I’m still not sure how exactly that race condition is happening, but I did remove some
__del__logic in 3.0 on the protocol that seems to have caused it to happen. Please try currentmainbranch if you’re able to. If it works, I’ll put out a patch release.