Multithread and locking issue
A multithreaded software written in Python is connected with a Postgres
database. To avoid concurrent access issue with the database, it starts
a thread who receive all SQL request via queue.put and queue.get (it
makes only insert, so no issue with the return of the SQL request).
As long as it runs with 10 threads, no issues. At 100 threads, the
software is blocked by what I think is a locking issue.
I guess Python multithreading and queue are working good enough that it
can handle 100 threads with no issue (give me wrong here), so I guess
the problem is in my code.
The function (thread) who handles SQL requests.
print("Start SQL Thread")
data = q.get(True,5)
print("RECEIVED SQL ORDER")
if data == "EXIT":
request = data['request']
arg = data['arg']
print("Can not execute SQL request")
The code to send the SQL request.
sql = dict()
sql['request'] = "update b2_user set credit = credit -%s where id = %s"
sql['arg'] = (i,username,)
print("Can not insert data")
The launch of the SQL thread (nothing fancy here).
q = qu.Queue()
t = th.Thread(target = execute_sql, args = (q,))
Any idea ?