-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
timestamping in smtplib.py to help troubleshoot server timeouts/delays #61118
Comments
I had cause to use smtplib to help me pinpoint why some outgoing mail was failing, but found that while it offered verbose logging (via debuglevel 1) this was without timestamps, making it difficult to make my case to the server operator that it was a server-side delay causing the issue. I've changed smtplib.py to add a second debugging level which includes timestamps down to microsecond granularity so that the debug log produced can pinpoint when a server isn't responding promptly. debuglevel 1 is unchanged, so anyone depending on the output from this being in a particular format won't be affected (either by setting debuglevel to "1" or "true"), but if debuglevel 2 is used explicitly then the standard output is preceded by a timestamp. |
Patch to add the same functionality to Python 2.7, if anyone's interested in that also. |
Here's a second path I've done for the current/default branch, using a separate print function for output, as recommended by Berker Peksag. I tried to add it as a separate patch set using the code review tool but every time I did, I just got a screen full of debug output from Django so I'm going to attach it here instead. The for loop on args inside _print_debug probably isn't ideal, but I've done this to try and make sure that debuglevel 1 output is identical to what it was before my patches. Because args is passed into _print_debug as a tuple, I found that when doing "print(message, args, file=stderr)" it introduced the extra parentheses and quotes inherent with a tuple into the output. By concatenating string representations of this tuple onto the existing string it means the original output format is duplicated exactly. There may be a speed penalty for this, but realistically it seems that a minor speed penalty would be expected when using debugging options and the output consistency trumps raw speed for debugging. Once I've found a way of achieving the same in 2.7 (i.e. maintaining the original output format when being passed a tuple, the approach I've used for Python 3 doesn't seem to have the desired affect in 2.7) then I'll hopefully submit a patch for that as well. |
Thanks for the suggestion and patch. I haven't reviewed it thoroughly yet, but if you change _print_debug to be: def _print_debug(*args): then print(datetime.datetime.now(), *args, file=stderr) should do what you want for python3 (I don't think the [] are needed, personally). This patch won't be applied to 2.7, which I presume you know, so making that work would be for informational purposes only. |
Er, that should have been (self, *args), but actually I'd recommend making it a module function, not a method, in which case my signature would be correct :) |
Thanks, I'll look into your suggestions and try to submit a further improved patch :) |
Moving this enhancement to python 3.5. I'm adding updated patch plus tests for debug messages, updated what's new docs |
Thanks Maciej. I left a couple of comments on Rietveld: http://bugs.python.org/review/16914/ |
Uploading updated version of the patch. |
After talking to David I'm submitting the patch once again with one slight change in ACKS file (I've put the names in the sorted order). |
Review comments added. |
Review comments addressed in latest patch. |
New changeset 65037930edb0 by R David Murray in branch 'default': |
New changeset de19c0ffe8d5 by R David Murray in branch 'default': |
New changeset 724473a18ada by R David Murray in branch 'default': |
Thanks Gavin and Maciej. I can tell it is the end of the sprints...my brain is fuzzy and I forgot both the news item and missed the missing versionchanged when I reviewed.... |
New changeset e532937914fc by R David Murray in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: