import cudf
import multiprocessing as mp
from sqlalchemy import create_engine
from datetime import datetime as dt
import pandas as pd
import logging

def t(df, u):
    st = dt.now()
    t = cudf.DataFrame()
    try:
        for i in range(len(df)):
            t = cudf.concat([t, df.iloc[i].to_frame().T], axis=0)
    except BaseException as e:
        print(e)
    t.loc[i + 1, 'HL'] = 1
    print(f'{u}完成,{dt.now() - st}')

if __name__ == '__main__':
    # mp.freeze_support()
    logger = mp.log_to_stderr()
    logger.setLevel(logging.DEBUG)
    engine = create_engine(
        'mysql+pymysql://root:r6kEwqWU9!v3@172.18.0.4:3306/qmt_stocks_whole?charset=utf8')

    # engine = create_engine(
    #     'mysql+pymysql://root:r6kEwqWU9!v3@localhost:3307/qmt_stocks_whole?charset=utf8')

    df = pd.read_sql_table('000001.SZ_1d', con=engine.connect())
    df = cudf.from_pandas(df)
    print(df.shape)
    # df_cudf = cudf.from_pandas(df)
    pool = mp.Pool(2)
    try:
        for j in range(1):
            pool.apply_async(func=t, args=(df, j))
        pool.close()
        pool.join()
    except BaseException as e:
        print(e)

