本文整理匯總了Python中lru.LRU屬性的典型用法代碼示例。如果您正苦於以下問題:Python lru.LRU屬性的具體用法?Python lru.LRU怎麽用?Python lru.LRU使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類lru
的用法示例。
在下文中一共展示了lru.LRU屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: check
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def check(self, host_port, key):
"""
判斷key是否存在於lru中,不存在則加入
Parameters:
host_port - host + "_" + str(port) 組成的字符串,指定查找的LRU
key - 在LRU中查找的key
Raises:
KeyError - key不存在於LRU中
"""
try:
target_lru = self.lru_dict[host_port]
except KeyError:
self.lru_dict[host_port] = lru.LRU(self.max_size)
self.lru_dict[host_port][key] = None
raise KeyError
try:
target_lru[key]
except KeyError:
target_lru[key] = None
raise KeyError
示例2: __init__
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def __init__(self, trading_calendar, reader, equity_adjustment_reader,
asset_finder,
roll_finders=None,
sid_cache_size=1000,
prefetch_length=0):
self.trading_calendar = trading_calendar
self._asset_finder = asset_finder
self._reader = reader
self._adjustment_readers = {}
if equity_adjustment_reader is not None:
self._adjustment_readers[Equity] = \
HistoryCompatibleUSEquityAdjustmentReader(
equity_adjustment_reader)
if roll_finders:
self._adjustment_readers[ContinuousFuture] =\
ContinuousFutureAdjustmentReader(trading_calendar,
asset_finder,
reader,
roll_finders,
self._frequency)
self._window_blocks = {
field: ExpiringCache(LRU(sid_cache_size))
for field in self.FIELDS
}
self._prefetch_length = prefetch_length
示例3: __init__
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def __init__(self, *args, cache=None, **kwargs):
arg_names = self._meta.field_names or ()
validate_args_and_kwargs(args, kwargs, arg_names)
field_values = merge_kwargs_to_args(args, kwargs, arg_names)
# Ensure that all the fields have been given values in initialization
if len(field_values) != len(arg_names):
raise TypeError(
"Argument count mismatch. expected {0} - got {1} - missing {2}".format(
len(arg_names),
len(field_values),
",".join(arg_names[len(field_values) :]),
)
)
for value, attr in zip(field_values, self._meta.field_attrs or ()):
setattr(self, attr, make_immutable(value))
self.cache = LRU(DEFAULT_CACHE_SIZE) if cache is None else cache
示例4: delete_key
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def delete_key(self, host_port, key):
"""
在LRU中刪除指定的key
Parameters:
host_port - host + "_" + str(port) 組成的字符串,指定刪除的key所在的LRU
key - 在LRU中刪除的key
"""
try:
target_lru = self.lru_dict[host_port]
del target_lru[key]
except KeyError:
pass
示例5: clean_lru
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def clean_lru(self, host_port):
"""
清空LRU
Parameters:
host_port - host + "_" + str(port) 組成的字符串,指定清空的LRU
"""
self.lru_dict.pop(host_port, None)
示例6: __init__
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def __init__(self):
self._cache = LRU(30)
self._LRULock = threading.RLock()
示例7: reset_cache
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def reset_cache(self) -> None:
self._cached_values = LRU(self._cache_size)
示例8: __init__
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def __init__(self,
chain_db: ChainDatabaseAPI,
epoch_length: int) -> None:
self._chain_db = chain_db
self._epoch_length = epoch_length
self._snapshots = lru.LRU(IN_MEMORY_SNAPSHOTS)
示例9: clear
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def clear(self) -> None:
self._cached_values = LRU(self._cache_size)
示例10: __init__
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def __init__(self, cache_size):
self.certificates = LRU(cache_size)
示例11: clear_cache
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def clear_cache(self):
if self._caches is None:
self._caches = LRU(self.MAX_CACHE_SPACE // self.CACHE_LENGTH)
else:
self._caches.clear()
示例12: __init__
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def __init__(self, rootdir=FXDAYU_BUNDLE_PATH, sid_cache_size=1000, converter=StockBarConverter,
trading_session=ASTOCK_TRADING_SESSION):
minutes_dir = os.path.join(rootdir if rootdir is not None else FXDAYU_BUNDLE_PATH, "minutes")
super(AStockBcolzMinuteBarReader, self).__init__(minutes_dir, sid_cache_size=sid_cache_size)
self._index_skip_suspending = LRU(sid_cache_size)
self._converter = converter
self._minute_index = _calc_minute_index(self._market_opens, trading_session)
示例13: __init__
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def __init__(self):
self.cache = LRU(400)
self.input_shape = None
self.nb_classes = None
self.model = None
self.config = None
示例14: __init__
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def __init__(self, model_ctx=mx.cpu(), data_ctx=mx.cpu()):
self.cache = LRU(400)
self.input_shape = None
self.nb_classes = None
self.model = None
self.config = None
self.model_ctx = model_ctx
self.data_ctx = data_ctx
示例15: __init__
# 需要導入模塊: import lru [as 別名]
# 或者: from lru import LRU [as 別名]
def __init__(self, rootdir, sid_cache_size=1000):
self._rootdir = rootdir
metadata = self._get_metadata()
self._start_session = metadata.start_session
self._end_session = metadata.end_session
self.calendar = metadata.calendar
slicer = self.calendar.schedule.index.slice_indexer(
self._start_session,
self._end_session,
)
self._schedule = self.calendar.schedule[slicer]
self._market_opens = self._schedule.market_open
self._market_open_values = self._market_opens.values. \
astype('datetime64[m]').astype(np.int64)
self._market_closes = self._schedule.market_close
self._market_close_values = self._market_closes.values. \
astype('datetime64[m]').astype(np.int64)
self._default_ohlc_inverse = 1.0 / metadata.default_ohlc_ratio
ohlc_ratios = metadata.ohlc_ratios_per_sid
if ohlc_ratios:
self._ohlc_inverses_per_sid = (
valmap(lambda x: 1.0 / x, ohlc_ratios))
else:
self._ohlc_inverses_per_sid = None
self._minutes_per_day = metadata.minutes_per_day
self._carrays = {
field: LRU(sid_cache_size)
for field in self.FIELDS
}
self._last_get_value_dt_position = None
self._last_get_value_dt_value = None
# This is to avoid any bad data or other performance-killing situation
# where there a consecutive streak of 0 (no volume) starting at an
# asset's start date.
# if asset 1 started on 2015-01-03 but its first trade is 2015-01-06
# 10:31 AM US/Eastern, this dict would store {1: 23675971},
# which is the minute epoch of that date.
self._known_zero_volume_dict = {}