ding.utils.data.structure.cache¶
ding.utils.data.structure.cache
¶
Cache
¶
Overview
Data cache for reducing concurrent pressure, with timeout and full queue eject mechanism
Interfaces:
__init__, push_data, get_cached_data_iter, run, close
Property:
remain_data_count
remain_data_count
property
¶
Overview
Return receive queue's remain data count
Returns:
- count (:obj:int): The size of the receive queue.
__init__(maxlen, timeout, monitor_interval=1.0, _debug=False)
¶
Overview
Initialize the cache object.
Arguments:
- maxlen (:obj:int): Maximum length of the cache queue.
- timeout (:obj:float): Maximum second of the data can remain in the cache.
- monitor_interval (:obj:float): Interval of the timeout monitor thread checks the time.
- _debug (:obj:bool): Whether to use debug mode or not, which enables debug print info.
push_data(data)
¶
Overview
Push data into receive queue, if the receive queue is full(after push), then push all the data in receive queue into send queue.
Arguments:
- data (:obj:Any): The data which needs to be added into receive queue
.. tip:: thread-safe
get_cached_data_iter()
¶
Overview
Get the iterator of the send queue. Once a data is pushed into send queue, it can be accessed by this iterator. 'STOP' is the end flag of this iterator.
Returns:
- iterator (:obj:callable_iterator) The send queue iterator.
run()
¶
Overview
Launch the cache internal thread, e.g. timeout monitor thread.
close()
¶
Overview
Shut down the cache internal thread and send the end flag to send queue's iterator.
dprint(s)
¶
Overview
In debug mode, print debug str.
Arguments:
- s (:obj:str): Debug info to be printed.
Full Source Code
../ding/utils/data/structure/cache.py