【发布时间】:2021-05-07 21:04:25
【问题描述】:
我正在尝试在多线程中运行以下代码,但是我不断收到“分段错误(核心转储)”。请告知我做错了什么-
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 是一个函数,用于在作为参数传递的表(API_Response)中插入记录以及其他值。 email_notifier 是一个在异常情况下发送电子邮件的功能。由于我在 API 中有 95k+ 条记录,因此尝试实现多线程逻辑。
谢谢 萨米!!
【问题讨论】:
标签: python multithreading segmentation-fault