If the rates for a bucket change, the schedule_leak method does not update because of the use of a forever loop. This means that it can possibly leak valid items since it only considers the old rates. To fix this the sync version of the loop (def _leak_task_sync()) can have a flag instead of being while(True). Also, the sync version containing
thread = Thread(target=_leak_task_sync, daemon=True)
thread.start()
works with the addition of the flag as mentioned previously but will create an error when a large quantity of different buckets are created. You can run out of threads which will create an error. You could consider using a thread pool to limit the number of threads that can be used.
If the rates for a bucket change, the schedule_leak method does not update because of the use of a forever loop. This means that it can possibly leak valid items since it only considers the old rates. To fix this the sync version of the loop (def _leak_task_sync()) can have a flag instead of being while(True). Also, the sync version containing thread = Thread(target=_leak_task_sync, daemon=True) thread.start() works with the addition of the flag as mentioned previously but will create an error when a large quantity of different buckets are created. You can run out of threads which will create an error. You could consider using a thread pool to limit the number of threads that can be used.