[Twisted-Python] what's a workaround for Ticket #3472 (sendmail has no timeout)?

Dave Britton dave at davebritton.com
Sat Aug 1 12:54:04 MDT 2009


Trying to implement a custom mail service I have run into the problem that
this ticket describes:
====
Ticket #3472 (new defect )
Opened 10 months ago
Last modified 10 months ago
twisted.mail.smtp sendmail() should [have] parameters to be passed for the
retry and timeout logic supported by SMTPClientFactory:
The method: def sendmail() spawns SMTPSenderFactories without a default
timeout value. These cause factories to wait forever if there is no response
from the remote server. On prolonged periods of time, stale
SMTPSenderFactories accumulates and will cause file descriptors to ran out
(Couldn't bind: 24: Too many open files.)
====
What would be the best way for me to work around this?
Specifically, when I use twisted.mail.smtp sendmail() for a lengthy list, I
fairly quickly get the "too many open files" message.

I tried using a coiterator to send small enough batches of emails, waiting
for each batch to be done before sending the next, because the "too many
files" error seemed to be caused by creating too many deferreds when a too
large batch of emails was sent at once. This worked in a test simulation,
but with real emails the system never completes the batch, it just hangs
waiting for sendmail to return.

Is there a best timeout mechanism I should use to force sendmail's return?
What I can think of so far are these:
option 1: Call setTimeout() on the deferred returned by sendmail despite
this warning in the  source for Deferred.setTimeout():
"warnings.warn("Deferred.setTimeout is deprecated.  Look for timeout support
specific to the API you are using instead.", DeprecationWarning,
stacklevel=2).
or option2: Patch a timeout argument into sendmail to have it passed to
SMTPSenderFactory(from_addr, to_addrs, msg, d)? Would this work? I can't
figure out how or if SMTPSenderFactory would handle a timeout argument.

Sorry for the long message. Thanks for your advice!
-Dave





More information about the Twisted-Python mailing list