簡體   English   中英

多線程 Python 問題(分段錯誤)

[英]MultiThreading Python Issue(Segmentation fault)

我正在嘗試在多線程中運行以下代碼,但是我不斷收到“分段錯誤(核心轉儲)”。 請告知我做錯了什么-

def insert_api(r):
    url = url_responses+'/'+str(r[0])
    response = requests.get(url,headers={'api-key':APIToken,'Content-Type': 'application/json'})
    if response.status_code == 200:
        dd = json.loads(response.content)
        InsertTable('API_Response',str(r[0]),str(r[1]),json.dumps(dd['result']))        
    else:
        logMsg('','HTTP request for '+url_responses+' failed. HTTP response code is: '+str(response.status_code),'failure')
        subject='API Request failed *********                  '+ datetime.now().strftime("%Y%m%d-%H%M")
        Body='This email is to notify that the API request for the URL: ' +str(url)+' failed at '+ datetime.now().strftime("%Y%m%d-%H%M")
        email_notifier(subject,Body)

with concurrent.futures.ThreadPoolExecutor() as executor:
    executor.map(insert_api,response_list)


InsertTable 是一個 function 用於在作為參數傳遞的表(API_Response)中插入記錄以及其他值。 email_notifier 是一個 function 用於在異常情況下發送電子郵件。 由於我在 API 中有 95k+ 條記錄,因此嘗試實現多線程邏輯。

謝謝薩米!!

我能夠通過在我的 InsertTable function 之前添加鎖定邏輯來解決它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM