我不知道我的 ThreadPoolExecutor 中发生了什么

I don't know what happens in my ThreadPoolExecutor

我正在尝试创建一个自动化程序,通过它的 API 异步使用 concurrent.futures.ThreadPoolExecutor 在 Zabbix 中注册主机,如您在这段代码中所见:

def zabbix_create_host(name, ip):
    session = get_session()
    token = get_token()
    print("     "+name+" "+ip)

    headers = {'Content-type': 'application/json'}
    data = '{"jsonrpc": "2.0","method": "host.create","params": {"host": "'+name+'","interfaces": [{"type": 2,"main": 1,"useip": 1,"ip": "'+ip+'","dns": "","port": "10050"}],"groups": [{"groupid": "5"}],"templates": [],"macros": [{"macro": "{$USER_ID}","value": "123321"}],"inventory_mode": 0,"inventory": {"macaddress_a": "01234","macaddress_b": "56768"}},"auth": "'+token+'","id": 1}'
    response = requests.post('http://127.0.0.1/api_jsonrpc.php', headers=headers, data=data)
    response = response.json()

def zabbix_create_host_multiple(names, ips):
    with concurrent.futures.ThreadPoolExecutor(max_workers=12) as executor:
        df = pd.concat(executor,map(zabbix_create_host, names, ips))
    return df

NAMES = ['PC1', 'PC2', 'PC3']
IPS = ['1.1.1.1', '2.2.2.2', '3.3.3.3']

zabbix_create_host_multiple(NAMES, IPS)

但是在执行代码时出现以下错误:

  File "main.py", line 159, in zabbix_create_hosts
    zabbix_create_host_multiple(names, ips)
  File "main.py", line 173, in zabbix_create_host_multiple
    df = pd.concat(executor,map(zabbix_create_host, names, ips))
  File "/home/sacarino/anaconda3/envs/aZabbix/lib/python3.8/site-packages/pandas/core/reshape/concat.py", line 274, in concat
    op = _Concatenator(
  File "/home/sacarino/anaconda3/envs/aZabbix/lib/python3.8/site-packages/pandas/core/reshape/concat.py", line 328, in __init__
    objs = list(objs)
TypeError: 'ThreadPoolExecutor' object is not iterable

让我们看看你能不能帮助我,这是我第一次使用这个

def zabbix_create_host(name, ip):
    session = get_session()
    token = get_token()
    print("     "+name+" "+ip)

    headers = {'Content-type': 'application/json'}
    data = '{"jsonrpc": "2.0","method": "host.create","params": {"host": "'+name+'","interfaces": [{"type": 2,"main": 1,"useip": 1,"ip": "'+ip+'","dns": "","port": "10050"}],"groups": [{"groupid": "5"}],"templates": [],"macros": [{"macro": "{$USER_ID}","value": "123321"}],"inventory_mode": 0,"inventory": {"macaddress_a": "01234","macaddress_b": "56768"}},"auth": "'+token+'","id": 1}'
    response = requests.post('http://127.0.0.1/api_jsonrpc.php', headers=headers, data=data)
    response = response.json()
    return pd.Series(response)

def zabbix_create_host_multiple(names, ips):
    df = pd.DataFrame()
    with concurrent.futures.ThreadPoolExecutor(max_workers=12) as executor:
        df = df.append(list(map(zabbix_create_host, names, ips)))
    return df

NAMES = ['PC1', 'PC2', 'PC3']
IPS = ['1.1.1.1', '2.2.2.2', '3.3.3.3']

zabbix_create_host_multiple(NAMES, IPS)

按系列返回响应并将其附加到数据帧