ratelimiter
ratelimiter copied to clipboard
Fix warning that coroutine decorator is deprecated since Python 3.8
Our project currently uses ratelimiter-1.2.0.post0, the latest version on PyPI.
Python 3.8 has been released and we're adding a py28 CI test for our project, which resulted in the following warning:
/home/travis/virtualenv/python3.8.0/lib/python3.8/site-packages/ratelimiter.py:127: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
__aexit__ = asyncio.coroutine(__exit__)
While the master branch has unreleased commits that weren't in the version we're testing, I believe the warning would still occur on the latest master commit at the following line:
https://github.com/RazerM/ratelimiter/blob/da78a45867c3a204083c6ea8ee74f6b3e78ef524/ratelimiter/_async.py#L35
Is it possible to update the code to no longer create the warning and release a new version to PyPI with the update?
Ping @RazerM
Can you submit a PR?
Can you submit a PR?
I read a bit about the difference between @asyncio.coroutine and async def. But I'm not familiar enough with Python's async to confidently fix the warning.
i'm running into the same issue. it looks like theres other issues with the async implementation here, its protecting async.Lock initialization with a the synchronous thread lock, and at the moment for exit it just calls through to baseclass exit, which is just using the thread lock not the async lock. putting an async coroutine around a blocking call doesn't make it not blocking
Can you submit a PR?
I read a bit about the difference between
@asyncio.coroutineandasync def. But I'm not familiar enough with Python's async to confidently fix the warning.
fwiw, in the context of the usage here the delta really isn't very material afaics.
The deprecated asyncio.coroutine was scheduled for removal in Python 3.10, but that didn’t end up happening. However, it is removed in current development versions of Python 3.11, so this still needs to be dealt with.
FYI this was officially removed in Python 3.11 so dependent packages are now breaking. @RazerM
Also seeing this. If this isn't going to be fixed is there an alternative?
Snakemake might switch to throttler instead: https://github.com/snakemake/snakemake/pull/1958
Hello folks, it's kinda self-promoting, but since this repo was not updated since 2018 consider using https://github.com/uburuntu/throttler for async cases -- it has pretty close syntax and is a bit more efficient.
Migration for context managers
from ratelimiter import RateLimiter
rate_limiter = RateLimiter(max_calls=10, period=1)
with rate_limiter:
do_something()
⇾
from throttler import Throttler
rate_limiter = Throttler(rate_limit=10, period=1)
async with rate_limiter:
await do_something()
https://github.com/uburuntu/throttler#simple-example
Migration for decorators
from ratelimiter import RateLimiter
@RateLimiter(max_calls=10, period=1)
def do_something():
pass
⇾
from throttler import throttle
@throttle(rate_limit=10, period=1)
async def do_something():
pass
https://github.com/uburuntu/throttler#throttler-and-throttlersimultaneous
Migration example
https://github.com/snakemake/snakemake/pull/1958
@uburuntu your project is already mentioned in this issue and in the other PR which I think is more than enough.