Python: 用for循环插入数据没有超时报错

Python: Insert data with for loop without timeout error

我需要按年分批插入数据,但我得到了

Error on %Server% ping: timed out. Connection was closed, reconnecting.

而且我不知道每次插入会持续多长时间。

我想我应该使用异步?

import pandas as pd
from clickhouse_driver import Client

client = Client(host, user=user, password=password, database = 'default')

dr = pd.date_range(start='1979-01-01', end='2029-01-31') # date ranges
for i in range(0,len(dr)):
    year  = dr[i].year
    query = f"insert into t2 select * from t1 where y = {year}"
    client.execute(query)

调整send_receive_timeout

client = Client(host, user=user, password=password, database = 'default', send_receive_timeout = 1000)

https://github.com/mymarilyn/clickhouse-driver/issues/196