@@ -85,15 +85,6 @@ def decorate(target):
8585 import backoff ._async
8686 retry = backoff ._async .retry_predicate
8787
88- elif _is_event_loop () and _is_current_task ():
89- # Verify that sync version is not being run from coroutine
90- # (that would lead to event loop hiccups).
91- raise TypeError (
92- "backoff.on_predicate applied to a regular function "
93- "inside coroutine, this will lead to event loop "
94- "hiccups. Use backoff.on_predicate on coroutines in "
95- "asynchronous code." )
96-
9788 if retry is None :
9889 retry = _sync .retry_predicate
9990
@@ -174,14 +165,6 @@ def decorate(target):
174165 if asyncio .iscoroutinefunction (target ):
175166 import backoff ._async
176167 retry = backoff ._async .retry_exception
177- elif _is_event_loop () and _is_current_task ():
178- # Verify that sync version is not being run from coroutine
179- # (that would lead to event loop hiccups).
180- raise TypeError (
181- "backoff.on_exception applied to a regular function "
182- "inside coroutine, this will lead to event loop "
183- "hiccups. Use backoff.on_exception on coroutines in "
184- "asynchronous code." )
185168
186169 if retry is None :
187170 retry = _sync .retry_exception
@@ -193,25 +176,3 @@ def decorate(target):
193176
194177 # Return a function which decorates a target with a retry loop.
195178 return decorate
196-
197-
198- def _is_event_loop (): # pragma: no cover
199- import asyncio
200-
201- try :
202- if sys .version_info >= (3 , 7 ):
203- asyncio .get_running_loop ()
204-
205- asyncio .get_event_loop ()
206- except RuntimeError :
207- return False
208- else :
209- return True
210-
211-
212- def _is_current_task (): # pragma: no cover
213- import asyncio
214- if sys .version_info >= (3 , 7 ):
215- return asyncio .current_task () is not None
216-
217- return asyncio .Task .current_task () is not None
0 commit comments