mysql连接与python中的concurrent.futures不兼容

mysql连接与python中的concurrent.futures不兼容,python,mysql,multithreading,concurrent.futures,Python,Mysql,Multithreading,Concurrent.futures,我正在尝试从 当我运行这个程序时,每次运行都会得到不同的错误 alok@alok-HP-Laptop-14s-cr1xxx:~/tmp$ python3 threadmysql.py 0 generated an exception: bytearray index out of range 1 generated an exception: MySQL Connection not available. 3 generated an exception: MySQL Connection no

我正在尝试从

当我运行这个程序时,每次运行都会得到不同的错误

alok@alok-HP-Laptop-14s-cr1xxx:~/tmp$ python3 threadmysql.py
0 generated an exception: bytearray index out of range
1 generated an exception: MySQL Connection not available.
3 generated an exception: MySQL Connection not available.
4 generated an exception: MySQL Connection not available.
2 generated an exception: MySQL Connection not available.

alok@alok-HP-Laptop-14s-cr1xxx:~/tmp$ python3 threadmysql.py
status 0 done
malloc(): corrupted top size
Aborted (core dumped)

alok@alok-HP-Laptop-14s-cr1xxx:~/tmp$ python3 threadmysql.py
0 generated an exception: bytearray index out of range
python3: malloc.c:2392: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
Aborted (core dumped)

为什么每次都会出错?使用mysql连接池解决了这个问题。如何创建池在

或者这个代码的简单版本是

import mysql.connector
import concurrent.futures

POOL_SIZE = 5
db = mysql.connector.connect(user=mysql_user, database='wallet', password=mysql_password, port='5009', host='localhost', pool_name = "mypool", pool_size = POOL_SIZE+1)

def work(i):
    db = mysql.connector.connect(pool_name = "mypool")
    cursor = db.cursor()
    cursor.execute('show tables;')
    db.close()
    return f'{i} done'

executor = concurrent.futures.ThreadPoolExecutor(max_workers=POOL_SIZE)
for i in range(1, 100):
    executor.submit(work, i)

print('done')
import os
import mysql.connector
import concurrent.futures

POOL_SIZE = 5

db = mysql.connector.connect(user=mysql_user, database='wallet', password=mysql_password, port='5009', host='localhost', pool_name = "mypool", pool_size = POOL_SIZE+1)

def work(i):
    db = mysql.connector.connect(pool_name = "mypool")
    cursor = db.cursor()
    cursor.execute('show tables;')
    db.close()
    return f'{i} done'

with concurrent.futures.ThreadPoolExecutor(max_workers=POOL_SIZE) as executor:
    future_to_uid = {executor.submit(work, i): i for i in range(5)}
    for future in concurrent.futures.as_completed(future_to_uid):
        uid = future_to_uid[future]
        try:
            data = future.result()
        except Exception as exc:
            print('%r generated an exception: %s' % (uid, exc))
        else:
            print('status', data)
import mysql.connector
import concurrent.futures

POOL_SIZE = 5
db = mysql.connector.connect(user=mysql_user, database='wallet', password=mysql_password, port='5009', host='localhost', pool_name = "mypool", pool_size = POOL_SIZE+1)

def work(i):
    db = mysql.connector.connect(pool_name = "mypool")
    cursor = db.cursor()
    cursor.execute('show tables;')
    db.close()
    return f'{i} done'

executor = concurrent.futures.ThreadPoolExecutor(max_workers=POOL_SIZE)
for i in range(1, 100):
    executor.submit(work, i)

print('done')