Skip to content
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

Allow user to override the Limiter subclass check #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Cyberes
Copy link

@Cyberes Cyberes commented Jul 28, 2023

I added the arg ignore_subclass to Limiter to enable the user to skip the storage must be a subclass of StorageBase check.

Here is my use-case:

from multiprocessing.managers import BaseManager
from token_bucket import Limiter, MemoryStorage

class LimiterManager(BaseManager):
    pass

LimiterManager.register('Limiter', Limiter)
LimiterManager.register('MemoryStorage', MemoryStorage)

manager = LimiterManager()
manager.start()

self.manager.Limiter(rate=max_requests_per_second, capacity=max_requests_per_second, storage=self.manager.MemoryStorage(), ignore_subclass=True)

As you can see, I am using multiprocessing's BaseManager to share the Limiter and MemoryStorage objects with multiprocessing.Process() processes. Without ignore_subclass, the subclass check fails.

@codecov-commenter
Copy link

Codecov Report

Merging #27 (4d4a52f) into master (4d94f64) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master       #27   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines           67        67           
  Branches        10        10           
=========================================
  Hits            67        67           
Files Changed Coverage Δ
token_bucket/limiter.py 100.00% <100.00%> (ø)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants