diff --git a/backoff/_async.py b/backoff/_async.py index 82fd477..b9e8d3e 100644 --- a/backoff/_async.py +++ b/backoff/_async.py @@ -2,13 +2,14 @@ import datetime import functools import asyncio +import inspect from datetime import timedelta from backoff._common import (_init_wait_gen, _maybe_call, _next_wait) def _ensure_coroutine(coro_or_func): - if asyncio.iscoroutinefunction(coro_or_func): + if inspect.iscoroutinefunction(coro_or_func): return coro_or_func else: @functools.wraps(coro_or_func) @@ -47,10 +48,10 @@ def retry_predicate(target, wait_gen, predicate, on_giveup = _ensure_coroutines(on_giveup) # Easy to implement, please report if you need this. - assert not asyncio.iscoroutinefunction(max_tries) - assert not asyncio.iscoroutinefunction(jitter) + assert not inspect.iscoroutinefunction(max_tries) + assert not inspect.iscoroutinefunction(jitter) - assert asyncio.iscoroutinefunction(target) + assert inspect.iscoroutinefunction(target) @functools.wraps(target) async def retry(*args, **kwargs): @@ -124,8 +125,8 @@ def retry_exception(target, wait_gen, exception, giveup = _ensure_coroutine(giveup) # Easy to implement, please report if you need this. - assert not asyncio.iscoroutinefunction(max_tries) - assert not asyncio.iscoroutinefunction(jitter) + assert not inspect.iscoroutinefunction(max_tries) + assert not inspect.iscoroutinefunction(jitter) @functools.wraps(target) async def retry(*args, **kwargs): diff --git a/backoff/_decorator.py b/backoff/_decorator.py index 77ed8c2..ca5d0ff 100644 --- a/backoff/_decorator.py +++ b/backoff/_decorator.py @@ -1,5 +1,5 @@ # coding:utf-8 -import asyncio +import inspect import logging import operator from typing import Any, Callable, Iterable, Optional, Type, Union @@ -98,7 +98,7 @@ def decorate(target): log_level=giveup_log_level ) - if asyncio.iscoroutinefunction(target): + if inspect.iscoroutinefunction(target): retry = _async.retry_predicate else: retry = _sync.retry_predicate @@ -198,7 +198,7 @@ def decorate(target): log_level=giveup_log_level, ) - if asyncio.iscoroutinefunction(target): + if inspect.iscoroutinefunction(target): retry = _async.retry_exception else: retry = _sync.retry_exception