Skip to content

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