Skip to content

Log exception location #10

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions retry/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import logging
import os
import random
import sys
import time
import traceback

from functools import partial

@@ -23,7 +26,7 @@ def __retry_internal(f, exceptions=Exception, tries=-1, delay=0, max_delay=None,
:param backoff: multiplier applied to delay between attempts. default: 1 (no backoff).
:param jitter: extra seconds added to delay between attempts. default: 0.
fixed if a number, random if a range tuple (min, max)
:param logger: logger.warning(fmt, error, delay) will be called on failed attempts.
:param logger: logger.warning(fmt, *args) will be called on failed attempts.
default: retry.logging_logger. if None, logging is disabled.
:returns: the result of the f function.
"""
@@ -37,7 +40,10 @@ def __retry_internal(f, exceptions=Exception, tries=-1, delay=0, max_delay=None,
raise

if logger is not None:
logger.warning('%s, retrying in %s seconds...', e, _delay)
frame = traceback.extract_tb(sys.exc_info()[2], 2)[1]
path, line, func, src = frame
loc = '{}:{}'.format(os.path.basename(path), line)
logger.warning('%s: %s, retrying in %s seconds...', loc, e, _delay)

time.sleep(_delay)
_delay *= backoff