我正在尝试使用Python从TeraData下载数据,但是由于复杂的SQL连接,当前进程运行了12个小时。我尝试使用current.futures,但收到错误消息“在将来运行或挂起时,进程池中的进程突然终止。”我对此并不陌生,但仍在设法弄清楚。 python 3.7
import pyodbc
import pandas as pd
from concurrent.futures import ProcessPoolExecutor
def chunker(seq, size):
return (seq[pos:pos + size] for pos in range(0, len(seq), size))
def task():
for group in chunker(fDocNum3, 10): #fDocNum3 consists of data which I break into chuncks to use as input for SQL query
dataList = ""
dfToList = group['Column_name'].tolist()
for i in dfToList:
dataList += "'"+i+ "'" + ","
dataList=dataList[0:-1]
try:
DataSet1= pd.read_sql(("SOME COMPLEX QUERY where column in ( "+
dataList + ")",TDconn) #EDIT .. i hope this makes more sense.
return DataSet1
except:
dfToListEx = dfToListEx.append(dfToList, ignore_index=True)
continue
def main():
DataSet1 = pd.DataFrame()
#executor = ProcessPoolExecutor(max_workers=4)
with ProcessPoolExecutor(max_workers=3) as executor:
future = executor.submit(task)
fDataSet = fDataSet.append(DataSet1, ignore_index=True)
#print(future.done())
print(future.result())
if __name__ == '__main__':
main()