Skip to content
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

Closed
gac mannequin opened this issue Jan 10, 2013 · 17 comments
Closed

timestamping in smtplib.py to help troubleshoot server timeouts/delays #61118

gac mannequin opened this issue Jan 10, 2013 · 17 comments
Labels
expert-email stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@gac
Copy link
Mannequin

gac mannequin commented Jan 10, 2013

BPO 16914
Nosy @warsaw, @bitdancer, @berkerpeksag, @soltysh
Files
  • smtplib.py.patch: patch to smtplib.py (3.4) to add debuglevel 2
  • smtplib.py.27.patch: patch to smtplib.py (2.7) to add debuglevel 2
  • smtplib.34.patch: second version of smtplib.py (3.4) patch
  • issue16914.patch
  • issue16914.patch
  • issue16914.patch
  • issue16914.patch
  • 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:

    assignee = None
    closed_at = <Date 2015-04-16.21:26:16.077>
    created_at = <Date 2013-01-10.12:41:48.066>
    labels = ['type-feature', 'library', 'expert-email']
    title = 'timestamping in smtplib.py to help troubleshoot server timeouts/delays'
    updated_at = <Date 2015-04-16.22:55:13.584>
    user = 'https://bugs.python.org/gac'

    bugs.python.org fields:

    activity = <Date 2015-04-16.22:55:13.584>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-04-16.21:26:16.077>
    closer = 'r.david.murray'
    components = ['Library (Lib)', 'email']
    creation = <Date 2013-01-10.12:41:48.066>
    creator = 'gac'
    dependencies = []
    files = ['28667', '28686', '28721', '38924', '38974', '39073', '39077']
    hgrepos = []
    issue_num = 16914
    keywords = ['patch']
    message_count = 17.0
    messages = ['179538', '179652', '179931', '179935', '179936', '180133', '240639', '240697', '240797', '241235', '241264', '241269', '241275', '241276', '241277', '241278', '241288']
    nosy_count = 6.0
    nosy_names = ['barry', 'r.david.murray', 'python-dev', 'berker.peksag', 'maciej.szulik', 'gac']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue16914'
    versions = ['Python 3.5']

    @gac
    Copy link
    Mannequin Author

    gac mannequin commented Jan 10, 2013

    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.

    @gac gac mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Jan 10, 2013
    @gac
    Copy link
    Mannequin Author

    gac mannequin commented Jan 11, 2013

    Patch to add the same functionality to Python 2.7, if anyone's interested in that also.

    @gac
    Copy link
    Mannequin Author

    gac mannequin commented Jan 14, 2013

    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.

    @bitdancer
    Copy link
    Member

    bitdancer commented Jan 14, 2013

    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.

    @bitdancer
    Copy link
    Member

    bitdancer commented Jan 14, 2013

    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 :)

    @gac
    Copy link
    Mannequin Author

    gac mannequin commented Jan 17, 2013

    Thanks, I'll look into your suggestions and try to submit a further improved patch :)

    @soltysh
    Copy link

    soltysh commented Apr 13, 2015

    Moving this enhancement to python 3.5. I'm adding updated patch plus tests for debug messages, updated what's new docs

    @berkerpeksag
    Copy link
    Member

    berkerpeksag commented Apr 13, 2015

    Thanks Maciej. I left a couple of comments on Rietveld: http://bugs.python.org/review/16914/

    @soltysh
    Copy link

    soltysh commented Apr 13, 2015

    Uploading updated version of the patch.

    @soltysh
    Copy link

    soltysh commented Apr 16, 2015

    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).

    @bitdancer
    Copy link
    Member

    bitdancer commented Apr 16, 2015

    Review comments added.

    @soltysh
    Copy link

    soltysh commented Apr 16, 2015

    Review comments addressed in latest patch.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 16, 2015

    New changeset 65037930edb0 by R David Murray in branch 'default':
    bpo-16914: add timestamps to smtplib debugging output via new debuglevel 2.
    https://hg.python.org/cpython/rev/65037930edb0

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 16, 2015

    New changeset de19c0ffe8d5 by R David Murray in branch 'default':
    News item for bpo-16914.
    https://hg.python.org/cpython/rev/de19c0ffe8d5

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 16, 2015

    New changeset 724473a18ada by R David Murray in branch 'default':
    bpo-16914: reflow paragraph and add missing versionchanged.
    https://hg.python.org/cpython/rev/724473a18ada

    @bitdancer
    Copy link
    Member

    bitdancer commented Apr 16, 2015

    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....

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 16, 2015

    New changeset e532937914fc by R David Murray in branch 'default':
    bpo-16914: fix test errors under -W error::BytesWarning.
    https://hg.python.org/cpython/rev/e532937914fc

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    expert-email stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants