Context: Django(3) commands, MySQL
from django.db import connections
...
def func1(a):
with connections['second_db'].cursor() as cursor:
cursor.execute(statement)
def func2(b):
with connections['second_db'].cursor() as cursor:
cursor.execute(statement)
for ...:
pool = ThreadPool(processes=2)
result1_proc = pool.apply_async(func1, args=(a))
result2_proc = pool.apply_async(func2, args=(b))
pool.close()
pool.join()
At some point i will get "Too many connections" error from server.
If i add "connections['second_db'].close()" at the end of each function, i get the "django.db.utils.InterfaceError: (0, '')".
What is wrong?