python - Pandas to_sql threading error -
i'm trying adapt use of threading script writeback sql table
https://github.com/haolu23/misc/blob/master/tosql.py
i managed make work initially, when wanted processing prior writing back, gets load 100 records first chunk, , class 'typeerror' on log. i'm not familiar threading , need help.
def processdata(df, *args, **kargs): df = fxn1(df,param1,param2,param3,param4) df = fxn2(df,param1,param2,param3,param4) df = fxn3(df,param1,param2,param3,param4) df.to_sql(*args, **kargs) try: import threading def tosql(df, *args, **kargs): chunksize = 1000 initial_chunk = 100 if len(df) > chunksize: df.iloc[:initial_chunk, :].to_sql(*args, **kargs) processdata(df.iloc[:initial_chunk, :],*args, **kargs) if kargs['if_exists'] == 'replace': kargs['if_exists'] = 'append' workers = [] in range((len(df) - initial_chunk)//chunksize): t = threading.thread(target=lambda: processdata(df.iloc[initial_chunk+i*chunksize:initial_chunk+(i+1)*chunksize, :],*args, **kargs)) t.start() workers.append(t) processdata(df.iloc[initial_chunk+i*chunksize:initial_chunk+(i+1)*chunksize, :],*args, **kargs) [t.join() t in workers] engine = sqlconnect() tosql(df, tblname, engine, schema=sc, index=false, if_exists="append") except: print(sys.exc_info()[0])
Comments
Post a Comment