При использовании нескольких потоков для вызова функции сообщается TimeoutError 10060 - PullRequest
0 голосов
/ 16 мая 2019

Я пытаюсь получить информацию об акциях с сайта nse и использую библиотеку nsepy. Теперь, если я пытаюсь сделать параллельный запрос, используя потоки, то сообщается об ошибке 10600. Если я добавляю сон всего на 1 секунду, кажется, что код работает нормально. Любая идея, почему требуется эта задержка в 1 секунду.

from nsetools import Nse  
from nsepy import get_history  
from datetime import date  
import talib as ta  
import threading  
import time


def get_and_cal_RSI(stock_code):  
    stock_details = get_history(symbol=stock_code, start=date(2017,1,1),
                                end=date(2019,5,15)) 
    print("calculating rsi for " + stock_code)  
    close_arr = stock_details.get("Close")  
    rsi= ta.RSI(close_arr, 14)  
    rsi_value = rsi.get(date(2019,5,15))  
    if rsi_value is not None and rsi_value > 50 :  
        print(stock_code)


nse = Nse()  
all_stocks= nse.get_stock_codes()

for code, stock_name in all_stocks.items():  
    if not (code == 'SYMBOL'):  
        threading.Thread(target=get_and_cal_RSI, args=(code,)).start()    
        time.sleep(1) // adding this line makes the code work fine but its 
                         abit slow and without the sleep the following error is reported:
requests.exceptions.ConnectionError: ('Connection aborted.', TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None))
...