python多线程数据冲突,每个线程访问同一个列表元素。
三个定义的全局变量必须要没办法转为局部变量。
def process_item(month):
global json_data_object,pKmSFk8
lock =threading.Lock()
filed = request_data()
with lock:
json_data_object = {
"city": "杭州",
"month": month
}
pKmSFk8 = {
"appId": "3c9208efcfb2f5b843eec8d96de6d48a",
"method": "GETDAYDATA",
"timestamp": filed.timestamp(),
"clienttype": "WEB",
"object": json_data_object,
"secret": filed.secret()
}
time.sleep(1)
#print(json_data_object)
main_sql()
def main():
# 这是一个你想要迭代的列表
new = selecter()
items = new.month_list()
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
executor.map(process_item, items)