mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-19 17:56:43 +00:00
multithreading fix
This commit is contained in:
parent
5784bcee5c
commit
1de2bf81cd
@ -2,6 +2,7 @@ import time
|
|||||||
|
|
||||||
import atexit
|
import atexit
|
||||||
import siphash
|
import siphash
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
last_time_called = dict()
|
last_time_called = dict()
|
||||||
|
|
||||||
@ -30,11 +31,12 @@ def buffered(batch_size: int, flush_on_exit: bool = False):
|
|||||||
|
|
||||||
def decorate(func):
|
def decorate(func):
|
||||||
buffer = []
|
buffer = []
|
||||||
|
lock = Lock()
|
||||||
if flush_on_exit:
|
if flush_on_exit:
|
||||||
atexit.register(func, buffer)
|
atexit.register(func, buffer)
|
||||||
|
|
||||||
def wrapper(items):
|
def wrapper(items):
|
||||||
|
with lock:
|
||||||
for item in items:
|
for item in items:
|
||||||
buffer.append(item)
|
buffer.append(item)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user