python sql多并发

import concurrent.futures
import urllib.request
import pandas as pd
import numpy as np
from sqlalchemy import create_engine
import pymysql
engine2 = create_engine('mysql+pymysql://root:wxl3322335@localhost:3306/my_db?charset=utf8')

SQLS = ['select * from t1',
        'select * from t2']

def run_sql(sql):
    df=pd.read_sql(sql,con=engine2)
    return df

with concurrent.futures.ThreadPoolExecutor(max_workers=None) as executor:
    future_to_sql = {executor.submit(run_sql, sql): sql for sql in SQLS}
    df3=pd.merge([df.result() for df in [future for future in concurrent.futures.as_completed(future_to_sql)]][0],
         [df.result() for df in [future for future in concurrent.futures.as_completed(future_to_sql)]][1].drop_duplicates('id'),
         how='left',on='id')
df3

 

你可能感兴趣的:(mysql,python)