掘金社区

多线程的时候报错,错误1000Pinned highlighted

小丑皇 发表在问题反馈 2021-05-07 08:56:09

问题反馈
346
2
0

本来这段代码运行是正常的,但是我想用joblib多线程来运行,就报错了。。token是正确的。

代码:
Parallel(n_jobs=12)(delayed(cal_target_code)(i,yesterday,context) for i in target_codes)

`def cal_target_code(code,yesterday,context):
print('*****',code)
print('now',context.now)
print('yester',history_n(symbol=code, frequency='1d', end_time=yesterday,
fields='symbol, open, close, low, high, eob',count=1,adjust=ADJUST_PREV))
print('now',history(symbol=code, frequency='tick', start_time=(context.now-timedelta(minutes=5)),
end_time=context.now, fields='open, close, low, high, created_at',df=1,adjust=ADJUST_PREV).open.tolist())
global trading_stocks
try:
yesterday_close = history_n(symbol=code, frequency='1d', end_time=yesterday,
fields='symbol, open, close, low, high, eob',count=1,adjust=ADJUST_PREV)[0]['close']
current_data = history(symbol=code, frequency='tick', start_time=(context.now-timedelta(minutes=5)),
end_time=context.now, fields='open, close, low, high, created_at',df=1,adjust=ADJUST_PREV).open.tolist()[-1]

except:
    pass`

输出:
2021-05-07 08:54:37,771 WARNING [history.py:25] error code=1000, error info=错误或无效的token
2021-05-07 08:54:37,771 ERROR [query.py:92] 获取不到数据服务地址
Traceback (most recent call last):
File "D:\Anaconda\lib\site-packages\gm\api\query.py", line 50, in wrapper
return func(*args, **kw)
File "D:\Anaconda\lib\site-packages\gm\retrying.py", line 37, in wrapped_f
return Retrying(*dargs, **dkw).call(f, *args, **kw)
File "D:\Anaconda\lib\site-packages\gm\retrying.py", line 202, in call
raise attempt.get()
File "D:\Anaconda\lib\site-packages\gm\retrying.py", line 240, in get
six.reraise(self.value[0], self.value[1], self.value[2])
File "D:\Anaconda\lib\site-packages\six.py", line 703, in reraise
raise value
File "D:\Anaconda\lib\site-packages\gm\retrying.py", line 190, in call
attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
File "D:\Anaconda\lib\site-packages\gm\api\query.py", line 399, in history_n
return historyapi.get_history_n_bars(symbol=symbol, frequency=frequency,
File "D:\Anaconda\lib\site-packages\gm\model\history.py", line 120, in get_history_n_bars
self._init_addr()
File "D:\Anaconda\lib\site-packages\gm\model\history.py", line 27, in _init_addr
raise EnvironmentError("获取不到数据服务地址")
OSError: 获取不到数据服务地址

评论: 2
  • 掘金SDK为了使策略简单稳定,采用单线程方式,不支持多线程。用户进行多线程编程时需要自主维护多线程可能遇到的问题

    2021-05-10 08:48:29
  • @charkong 但是回测太慢了。。基本上需要一天以上。。时间长了就容易出一些奇怪的报错。。在本地使用多线程也能检测的到?。。

    2021-05-10 14:13:38

Looks like your connection to 掘金量化社区 - 量化交易者的交流社区 was lost, please wait while we try to reconnect.