D
D
dake12312018-04-14 20:00:19
MySQL
dake1231, 2018-04-14 20:00:19

How to interact with the database with multithreading?

Hello! I have a python worker that takes data from the database and then starts a thread with a loader. Initially, the status in the database is "in the queue", after the worker has picked up the status it becomes "in work", then the download goes in a separate thread, after the download is completed the status should be "ready", here is the problem, an error occurs

_mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now")

or something like this
2013, "Lost connection"
There is a class that works with the database, I pass an instance of this class to the class that works in the thread

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan., 2018-04-14
@LaRN

About the essence of the error is written here https://habrahabr.ru/post/21326/ or here www.mysql.ru/docs/man/Commands_out_of_sync.html
It is not clear how your database access class is implemented. But if all the workers go through one common connection, then the links indicate what is happening. For good, each worker should open its own connection to the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question