Last active
April 15, 2021 08:31
-
-
Save kakarukeys/53bfe2f52ec1db0fd5ac2c817b943eaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
from asyncio import Semaphore | |
MAX_CONNECTIONS_PER_MX = 1 | |
leaky_bucket = defaultdict(lambda: Semaphore(MAX_CONNECTIONS_PER_MX)) | |
async def ping_server_handler(request): | |
... | |
... | |
async with leaky_bucket[mx_domain]: | |
# only 1 await is allowed on smtp_handshake() at any time per every unique mx_domain | |
await smtp_handshake(mx_domain, email) | |
... | |
... | |
async def smtp_handshake(mx_domain, email): | |
... | |
await ..ehlo | |
await ..rcpt | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment