Skip to main content
fix parameter ordering
Source Link
Dan Oberlam
  • 8k
  • 2
  • 33
  • 74
def retry(func, *args, retry_count=5, delay=5, allowed_exceptions=(), *args, **kwargs):
    for _ in range(retry_count):
        try:
            result = func(*args, **kwargs)
            if result: return result
        except allowed_exceptions as e:
            pass
def retry(func, retry_count=5, delay=5, allowed_exceptions=(), *args, **kwargs):
    for _ in range(retry_count):
        try:
            result = func(*args, **kwargs)
            if result: return result
        except allowed_exceptions as e:
            pass
def retry(func, *args, retry_count=5, delay=5, allowed_exceptions=(), **kwargs):
    for _ in range(retry_count):
        try:
            result = func(*args, **kwargs)
            if result: return result
        except allowed_exceptions as e:
            pass
deleted 5 characters in body
Source Link
Dan Oberlam
  • 8k
  • 2
  • 33
  • 74
def retry(func, retry_count=5, delay=5, allowed_exceptions=(), *args, **kwargs):
    for _ in range(retry_count):
        try:
            result = func(*func_args*args, **kwargs)
            if result: return result
        except allowed_exceptions as e:
            pass
def retry(func, retry_count=5, delay=5, allowed_exceptions=(), *args, **kwargs):
    for _ in range(retry_count):
        try:
            result = func(*func_args, **kwargs)
            if result: return result
        except allowed_exceptions as e:
            pass
def retry(func, retry_count=5, delay=5, allowed_exceptions=(), *args, **kwargs):
    for _ in range(retry_count):
        try:
            result = func(*args, **kwargs)
            if result: return result
        except allowed_exceptions as e:
            pass
deleted 128 characters in body
Source Link
Dan Oberlam
  • 8k
  • 2
  • 33
  • 74
def retry(func, retry_count=5, delay=5, allowed_exceptions=(), *args, **kwargs):
    for _ in range(retry_count):
        try:
            result = func(*func_args, **kwargs)
            if result: return result
        except Exceptionallowed_exceptions as e:
            if e not in allowed_exceptions:
                raisepass
import functools
import asyncio    

def retry(retry_count=5, delay=5, allowed_exceptions=()):
    def decorator(f):
        @functools.wraps(f)
        async def wrapper(*args, **kwargs):
            result = None
            last_exception = None
            for _ in range(retry_count):
                try:
                    result = func(*func_args, **kwargs)
                    if result: return result
                except Exceptionallowed_exceptions as e:
                    if e not in allowed_exceptions:
                        raise
                    last_exception = e
                log.debug("Waiting for %s seconds before retrying again")
                await asyncio.sleep(delay)

            if last_exception is not None:
                raise type(last_exception) from last_exception
                # Python 2
                # import sys
                # raise type(last_exception), type(last_exception)(last_exception), sys.exc_info()[2]

            return result

        return wrapper
    return decorator
def retry(func, retry_count=5, delay=5, allowed_exceptions=(), *args, **kwargs):
    for _ in range(retry_count):
        try:
            result = func(*func_args, **kwargs)
            if result: return result
        except Exception as e:
            if e not in allowed_exceptions:
                raise
import functools
import asyncio    

def retry(retry_count=5, delay=5, allowed_exceptions=()):
    def decorator(f):
        @functools.wraps(f)
        async def wrapper(*args, **kwargs):
            result = None
            last_exception = None
            for _ in range(retry_count):
                try:
                    result = func(*func_args, **kwargs)
                    if result: return result
                except Exception as e:
                    if e not in allowed_exceptions:
                        raise
                    last_exception = e
                log.debug("Waiting for %s seconds before retrying again")
                await asyncio.sleep(delay)

            if last_exception is not None:
                raise type(last_exception) from last_exception
                # Python 2
                # import sys
                # raise type(last_exception), type(last_exception)(last_exception), sys.exc_info()[2]

            return result

        return wrapper
    return decorator
def retry(func, retry_count=5, delay=5, allowed_exceptions=(), *args, **kwargs):
    for _ in range(retry_count):
        try:
            result = func(*func_args, **kwargs)
            if result: return result
        except allowed_exceptions as e:
            pass
import functools
import asyncio    

def retry(retry_count=5, delay=5, allowed_exceptions=()):
    def decorator(f):
        @functools.wraps(f)
        async def wrapper(*args, **kwargs):
            result = None
            last_exception = None
            for _ in range(retry_count):
                try:
                    result = func(*func_args, **kwargs)
                    if result: return result
                except allowed_exceptions as e:
                    last_exception = e
                log.debug("Waiting for %s seconds before retrying again")
                await asyncio.sleep(delay)

            if last_exception is not None:
                raise type(last_exception) from last_exception
                # Python 2
                # import sys
                # raise type(last_exception), type(last_exception)(last_exception), sys.exc_info()[2]

            return result

        return wrapper
    return decorator
added 183 characters in body
Source Link
Dan Oberlam
  • 8k
  • 2
  • 33
  • 74
Loading
edited body
Source Link
Dan Oberlam
  • 8k
  • 2
  • 33
  • 74
Loading
Source Link
Dan Oberlam
  • 8k
  • 2
  • 33
  • 74
Loading