def _serve(self, nodes=None): #XXX: should be STATE method; use id """Create a new server if one isn't already initialized""" if nodes is None: nodes = self.__nodes _pool = __STATE['pool'] if not _pool or nodes != _pool.__nodes: _pool = Pool(nodes) _pool.__nodes = nodes __STATE['pool'] = _pool return _pool
def restart(self, force=False): "restart a closed pool" _pool = __STATE.get(self._id, None) if _pool and self.__nodes == _pool.__nodes: RUN = 0 if not force: assert _pool._state != RUN # essentially, 'clear' and 'serve' self._clear() _pool = Pool(self.__nodes) _pool.__nodes = self.__nodes __STATE[self._id] = _pool return _pool
def get_returns(tickers, folder=None, freq='d', fromdate='2000-01-01', todate='2018-12-31', forward_bars=None, data_col=None, is_log=False, is_debug=False, is_multiprocess=False): if data_col is None: data_col = 'Adj Close' res = {} tqdm, ascii = get_tqdm() logger = get_logger() logger.info('Loading Yahoo Labels...') def _get_return(ticker, res=res, folder=folder, freq=freq, fromdate=fromdate, todate=todate, is_debug=is_debug, forward_bars=forward_bars, data_col=data_col, is_log=is_log): if is_debug: logger = get_logger() logger.info('Loading %s' % ticker) res[ticker] = YahooProcessor._get_return(ticker, folder, freq, fromdate, todate, forward_bars, data_col, is_log) return ticker, res[ticker] if is_multiprocess: logger.info('Initalized Multiprocess To Get Returns...') with Pool(cpu_count()) as p: res_pool = list(tqdm(p.imap(_get_return, tickers), total=len(tickers), ascii=ascii)) res = {item[0]: item[1] for item in res_pool} else: list(tqdm(map(_get_return, tickers), total=len(tickers), ascii=ascii)) return res