mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-19 17:56:43 +00:00
Add buffered decorator
This commit is contained in:
parent
7506ddaf9a
commit
3adca8cb5e
@ -1,5 +1,6 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
|
import atexit
|
||||||
import siphash
|
import siphash
|
||||||
|
|
||||||
last_time_called = dict()
|
last_time_called = dict()
|
||||||
@ -25,6 +26,27 @@ def rate_limit(per_second):
|
|||||||
return decorate
|
return decorate
|
||||||
|
|
||||||
|
|
||||||
|
def buffered(batch_size: int, flush_on_exit: bool = False):
|
||||||
|
|
||||||
|
def decorate(func):
|
||||||
|
buffer = []
|
||||||
|
if flush_on_exit:
|
||||||
|
atexit.register(func, buffer)
|
||||||
|
|
||||||
|
def wrapper(*items):
|
||||||
|
|
||||||
|
for item in items:
|
||||||
|
buffer.append(item)
|
||||||
|
|
||||||
|
if len(buffer) >= batch_size:
|
||||||
|
func(buffer)
|
||||||
|
buffer.clear()
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
return decorate
|
||||||
|
|
||||||
|
|
||||||
Key = b"0123456789ABCDEF"
|
Key = b"0123456789ABCDEF"
|
||||||
|
|
||||||
|
|
||||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="hexlib",
|
name="hexlib",
|
||||||
version="1.2",
|
version="1.3",
|
||||||
description="Misc utility methods",
|
description="Misc utility methods",
|
||||||
author="simon987",
|
author="simon987",
|
||||||
author_email="me@simon987.net",
|
author_email="me@simon987.net",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user